phpSensei Posted November 16, 2007 Share Posted November 16, 2007 why is it that after the user gets alerted that the email is empty the page doesnt go to submitpage.htm, but when the name is alerted for being empty, the page loads to submitpage.html <html> <head> <script type="text/javascript"> function validate_required(field,alerttxt) { with (field) { if (value==null||value=="") { alert(alerttxt);return false } else { return true } } }function validate_form(thisform) { with (thisform) { if (validate_required(email,"Email must be filled out!")==false) { email.focus();return false } elseif(validate_required(name,"Name must be filled out!")==false) { name return false } } } </script> </head><body> <form action="submitpage.htm" onsubmit="return validate_form(this)" method="post"> <p>Email: <input type="text" name="email" size="30"> <input type="submit" value="Submit"> </p> <p>Name <label> <input name="name" type="text" id="name"> </label> </p> </form> </body></html> Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 16, 2007 Share Posted November 16, 2007 first of all there are some javascript errors on your page, when the name is alerted there is a javascript error and therefore it submits the page I modified your code following is the correct code you just put 'name' instead of name.focus() causing a javascript error <html> <head> <script type="text/javascript"> function validate_required(field,alerttxt) { with (field) { if (value==null||value=="") { alert(alerttxt); return false; } else { return true; } } } function validate_form(thisform) { with (thisform) { if (validate_required(email,"Email must be filled out!")==false) { email.focus(); return false; } else if(validate_required(name,"Name must be filled out!")==false) { name.focus(); return false; } } return true; } </script> </head> <body> <form action="submitpage.htm" onsubmit="return validate_form(this)" method="post"> <p>Email: <input type="text" name="email" size="30"> <input type="submit" value="Submit"> </p> <p>Name <label> <input name="name" type="text" id="name"> </label> </p> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
phpSensei Posted November 16, 2007 Author Share Posted November 16, 2007 thanks bro, much love <3 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.