Ok, I am reasonably new to javascript, and I have been trying to code some really basic client-side form validation. The validation part is working, but for some reason the form won't submit if no errors are found. I have tried all different variations of the submit syntax. i.e.
I would really appreciate any advise. Here is my code:
Many Thanks
document.login_form.submit();
. But settled with the one on W3Schools even though it still didn't work.I would really appreciate any advise. Here is my code:
Code:
<head> <title>Project Rival - Authentication</title> <link href="css/style.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> function verify() { var themessage = "Please enter your"; if (document.login_form.user.value=="") { themessage = themessage + " username"; } if (document.login_form.user.value=="" && document.login_form.pass.value=="") { themessage = themessage + " and"; } if (document.login_form.pass.value=="") { themessage = themessage + " password"; } //alert if fields are empty and cancel form submit if (document.login_form.user.value!="" && document.login_form.pass.value!="") { document.getElementById("login_form").submit(); return true; } else { document.getElementById("error").innerHTML = themessage; return false; } } </script> </head> <body> <div id="container"> <div id="login_box_top"> </div> <div id="logo"><img src="images/projectrival.jpg" width="150"/></div> <div id="error"></div> <div id="login"> <form action="login.php" method="post" name="login_form" id="login_form"> <input name="user" class="input" id="user" type="text" size="30" maxlength="30" /><br /><br /> <input name="pass" class="input" id="pass" type="password" size="30" maxlength="30" /><br /><br /> <input name="submit" id="submit" type="button" value="Login" onclick="verify()" /> </form> </div> <div id="login_box_bottom"> </div> <div id="copy"><p>© Martin Day 2011 </div> </div> </body> </html>

Comment