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> <input type="text" name="j_username" size="25" /> </p> <p><strong style="color: #e3f7ff">old password: </strong> <input type="password" size="25" name="j_old_password" /> </p> <p><strong style="color: #e3f7ff">new password: </strong> <input type="password" size="25" name="j_new_password" /> </p> <p><strong style="color: #e3f7ff">confirm new password: </strong> <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;
Comments
Post a Comment