html - validate form with javascript doesn't get triggered -


i have form change password, javascript validate check form fields, however, don't think javascript gets triggered. entering submit takes me straight null pointer exception error in controller. missing ?

<html xmlns="http://www.w3.org/1999/xhtml"> <head>     <meta http-equiv="content-type" content="text/html; charset=utf-8" />     <title>change password page</title>         <script type="text/javascript">         function validate(){              var username=document.form.j_username.value;             var oldpassword=document.form.j_old_password.value;             var newpassword=document.form.j_new_password.value;             var confirmpassword=document.form.j_confirm_password.value;              if(username==""){              alert("enter username!");               return false;                 }              if(oldpassword==""){              alert("enter old password!");               return false;                 }              if(newpassword==""){                  alert("enter new password!");                   return false;                 }              if(confirmpassword==""){                  alert("enter confirm password!");                   return false;                 }              return true;          }            </script> </head>  <body>     <div class="change_password-header">     <h1>blah blah</h1>     </div>     <div class="l" style="float: left; left; padding: 1em; background-color: #8eb4e3; border: 1px solid black;">     <form action="changepassword" method="post" onsubmit="return validate()">         <p><strong style="color: #e3f7ff">username: </strong>             &nbsp;<input type="text" name="j_username" size="25" />         </p>          <p><strong style="color: #e3f7ff">old password: </strong>             &nbsp;<input type="password" size="25" name="j_old_password" />         </p>          <p><strong style="color: #e3f7ff">new password: </strong>             &nbsp;<input type="password" size="25" name="j_new_password" />         </p>          <p><strong style="color: #e3f7ff">confirm new password: </strong>             &nbsp;<input type="password" size="25" name="j_confirm_password" />         </p>          <div style="text-align: center;">             <input type="submit" value="submit" class="button-login" style="background-color: #c7d9f1; border: 1px solid black;" />             <input type="reset" value="reset" class="button-login" style="background-color: #c7d9f1; border: 1px solid black;"/>         </div>     </form>     </div>      <div style="float: left; width: 100%; font-size: 12px; padding: 0 0 0 2em" class="change_password-footer">         <div><a href = "login">return login screen</a></div>         <br/>     </div>   </body> </html> 

you forgot name form:

<form action="changepassword" name="test" method="post" onsubmit="return validate()"> 

and reference in js this:

var username=document.forms.test.j_username.value; 

http://jsfiddle.net/gq79y/


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -