Hi I have the following form <form action="index.html" id="target"> <label>Email</label> <input id="email" type="text" name="name" required" /> <label">Password</label> <input id="pass" type="password" name="name" required" /> <button onclick="return ">Login</button> <button>Cancel</button> </div> </form> When user types "login" & "success" as a username and pass then only it should redirect to another page else not. That was the condition. And when he type "login" & "getin" it should redirect to another page. I have done this script type="text/javascript"> $('#target').submit(function() { var email = $('#email').val(); var pass = $('#pass').val(); if((email == "login") && (pass == "success")){ return true; } else{ return false; } }); It redirects to a single page. But cant able to get the second one. even i tried with window.alert. Please help me. Thanks
You can try window.location.replace method. Instead of returning true/false from ur javascript, you can redirect to the required page. // similar behavior as an HTTP redirect window.location.replace("http://scriptsplash.com"); // similar behavior as clicking on a link window.location.href = "http://scriptsplash.com"; Code (markup): Here's the jQuery Alternative var url = "http://scriptsplash.com"; $(location).attr('href',url); Code (markup):