jsp - How to check inequality between two strings in javascript -


i have jsp form shown below:

<form action="changepasswordservlet1" method="post" onsubmit="return matchpassword();"> <table id= "changepwd"> <tr> <td>username: </td> <td><input type="text" name="username" id="username" value="<%out.println( request.getsession().getattribute("user") );%>"></td> </tr> <tr> <td>old password: </td> <td><input type="password" name="oldpass" id="oldpass"><br/> <span id="errormissingoldpass" style="display:none"><font color="red">*please type in current password</font></span> </td> </tr> <tr> <td>new password: </td> <td><input type="password" name="newpass" id="newpass"><br/> <span id="errormissingnewpass" style="display:none"><font color="red">*please type in new password</font></span> </td> </tr> <tr> <td>confirm password: </td> <td><input type="password" name="confirmpass" id="confirmpass"><br/> <span id="errormissingconfirmpass" style="display:none"><font color="red">*please cofirm new password typing again</font></span> <span id="errormatchingpassword" style="display:none"><font color="red">*new password , confirm password don't match</font></span> </td> </tr> <tr>  <td><button type="submit" name="submit" id="submit">submit</button></td> </tr>   </table> </form> 

and javascript function validating form @ client side shown below:

function matchpassword(){     var valid = true;     var validationmessage = 'please correct following errors:\r\n';       document.getelementbyid('errormissingoldpass').style.display='none';     document.getelementbyid('errormissingnewpass').style.display='none';     document.getelementbyid('errormissingconfirmpass').style.display='none';     document.getelementbyid('errormatchingpassword').style.display='none';      if(document.getelementbyid('oldpass').value.length==0){         validationmessage = validationmessage + '  - please type current password\r\n';         document.getelementbyid('errormissingoldpass').style.display='';         valid = false;     }     else{         document.getelementbyid('errormissingoldpass').style.display='none';         }      if(document.getelementbyid('newpass').value.length==0){         validationmessage = validationmessage + '  - please type in new password\r\n';         document.getelementbyid('errormissingnewpass').style.display='';         valid = false;     }     else{         document.getelementbyid('errormissingnewpass').style.display='none';     }      if(document.getelementbyid('confirmpass').value.length==0){         validationmessage = validationmessage + '  - please type again new password cofirmation\r\n';         document.getelementbyid('errormissingconfirmpass').style.display='';         valid = false;     }     else{         document.getelementbyid('errormissingconfirmpass').style.display='none';     }      if(!(document.getelementbyid('newpass')===(document.getelementbyid('confirmpass')))){         validationmessage = validationmessage + '  - new password , confirm password donot match\r\n';         document.getelementbyid('errormatchingpassword').style.display='';         valid = false;     }      else{         document.getelementbyid('errormatchingpassword').style.display='none';     }     if (valid == false){         alert(validationmessage);         }         return valid;  } 

the problem here though type in same password in new password , confirm password errormatchingpassword getting displayed in jsp , not submitting form. please me solving this...

i tried this:

if((document.getelementbyid('newpass')!==(document.getelementbyid('confirmpass')))){             validationmessage = validationmessage + '  - new password , confirm password donot match\r\n'; 

but still problem persists. needed in advance...

you're comparing 2 elements, not values contained therein:

if((document.getelementbyid('newpass').value !==(document.getelementbyid('confirmpass').value))){   validationmessage = validationmessage + '  - new password , confirm password donot match\r\n'; } 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -