+ 2

The action page is loaded even I enter the wrong password and click ok the alert screen. Anyone please tell how to solve this...

<!DOCTYPE html> <html> <head> <script> function check(form) { if(form.userid.value == "admin" && form.pwd.value == "root") { document.location.href = "menu.html"; } else { alert("Incorrect Username or Password"); } } </script> <title>Login</title></head> <body> <form method="post" action="menu.html"> Username <input type="text" name="userid"><br> Password: <input type="Password" name="pwd"><br> <input type="submit" onclick="check(this.form)" value="Login"> </form> </body> </html>

6th Jan 2018, 2:22 AM
Bibek Oli
Bibek Oli - avatar
3 ответов
+ 6
Try this, not really sure why but it works : ) <!DOCTYPE html> <html> <head> <script> function check() { if(form1.userid.value == "admin" && form1.pwd.value == "root") { document.location.href = "menu.html"; } else { alert("Incorrect Username or Password"); event.preventDefault(); return false; } } </script> <title>Login</title></head> <body> <form id="form1" method="post" action="menu.html" onsubmit="check()"> <label>User Name</label> <input type="text" name="userid"><br> <label>Password</label>: <input type="Password" name="pwd"><br> <input type="submit" value="Login"> </form> </body> </html> Hth, cmiiw
6th Jan 2018, 4:03 AM
Ipang
+ 7
try removing the "menu.html" in the form action ,that attribute will automatically redirect the page to menu.html after the form is submitted (even if the password is wrong) so removing it will probably solve your problem.
6th Jan 2018, 3:04 AM
Leon lit
Leon lit - avatar
+ 6
idk. my login page that I posted several months ago did like this.
6th Jan 2018, 2:42 AM
Amethyst Animion
Amethyst Animion - avatar