How do I redirect users after submit button click? My javascript isn't working:
Javascript
<script type="text/javascript" language="javascript">
function redirect()
{
window.location.href="login.php";
}
</script>
Form Page
<form name="form1" id="form1" method="post">
<input type="submit" class="button4" name="order"
id="order" value="Place Order" onclick="redirect();" >
</form>
It would be
Your submission will cancel the redirect or vice versa.
I do not see the reason for the redirect in the first place since why do you have an order form that does nothing.
That said, here is how to do it. Firstly NEVER put code on the submit button but do it in the onsubmit, secondly return false to stop the submission
NOTE This code will IGNORE the action and ONLY execute the script due to the return false/preventDefault
using
Or unobtrusively:
using
jQuery:
-----
Example:
I hope this might be helpful
Why don't you use plain html?
In your login.php you can then use the header() function.
use
or
simply window.location("login.php");
It is better than using
window.location.href =,
becausereplace()
does not put the originating page in the session history, meaning the user won't get stuck in a never-ending back-button fiasco. If you want to simulate someone clicking on a link, uselocation.href
. If you want to simulate an HTTP redirect, uselocation.replace
.