You are calling the function in the submit event of the form so this happens:
- The form submission tells the browser to navigate to Y
- The browser navigates to Y
You need to prevent the default behaviour of the form submission to allow the navigation in step 1 to be followed through on.
Using an intrinsic event attribute, you need to
return false; at the end of your
onsubmit function. That could be by returning the return value of
f1 and then returning
false from there, or a second statement in the function.
A modern approach (i.e. the best practice for this century) would replace the
onsubmit attribute with
addEventListener and then call the
preventDefault method of the event object.