NathanLedet Posted July 21, 2008 Share Posted July 21, 2008 Javascript: function validate() { if(document.form2.client.value==''){ alert('Fill in the Username before submitting'); return false; }else{ return true; } if(document.form2.project.value==''){ alert('Fill in the Password before submitting'); return false; }else{ return true; } } and the HTML form: <form ACTION="client_login_process.php" id="form2" name="form2" method="POST" onSubmit='return validate();'> <label></label> <table width="241" border="0" align="center"> <tr> <td colspan="2"><h2 class="style4">Project Login</h2></td> </tr> <tr> <td width="79"><span class="style3"><strong> </strong> </span> <span class="style2"> </span> <div align="right" class="style3"><strong>Client:</strong></div> </td> <td width="152"><input name="client" type="text" id="client" tabindex="5" maxlength="20" /></td> </tr> <tr> <td><span class="style3"><strong> </strong> </span> <span class="style2"> </span> <div align="right" class="style3"><strong>Project:</strong></div> </td> <td><input name="project" type="text" id="project" tabindex="6" maxlength="20" /></td> </tr> <tr> <td> </td> <td><input name="submit1" type="submit" id="submit1" tabindex="8" value="Login" /></td> </tr> </table> </form> When I test this, only the 'client' will show the error message, but the 'project' never validates. Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 21, 2008 Share Posted July 21, 2008 Because upon the first validation you are returning true. Don't "return" until you want to exit the function. function validate() { if(!document.form2.client.value) { alert('Fill in the Username before submitting'); return false; } if(!document.form2.project.value) { alert('Fill in the Password before submitting'); return false; } return true; } 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.