Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

JavaScript
$('#btnSiteSave').click(function (e) {  

        var password=$('input[id$=password]').val();
        var confirmpassword=$('input[id$=cpassword]').val();
        if(password!=confirmpassword)
        {
          $("#cpassword").rules("add", {
          compare:true,
          messages: {
          }
          });
          }
                                       
    });


while click on save button i need to compare the password and confirm password.
this is the coding am tried but am not getting the output..

Pls help me to solve this.
Posted
v2
Comments
Sergey Alexandrovich Kryukov 16-Aug-12 5:32am    
Excuse me, help with what? "Not getting the output" is not informative. What did you want to get and what you actually got? Did you run it under the debugger?
--SA
ZurdoDev 16-Aug-12 8:09am    
What is $("#cpassword")? Is it a jquery plugin? Link to it so we know what you are talking about.

1 solution

You can try like this

XML
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">

function CheckValidation() {
$('#Error_pspan').html("");
if($('#password').val()!=$('#cpassword').val())
    {
     $('#Error_pspan').html("Password and Confirm Password are not matched");
                 $('#password').focus();
                 return false;
    }
}
</script>



XML
<b>Password:</b><input type="password" name="password" id="password"  /><br/>
<span id="Error_pspan" style="color:Red; font-size:12px; font-weight:bolder;"></span><br/>
<b>Confirm Password:</b><input type="password" name="cpassword" id="cpassword"  /><br/>

<button type="Button" onclick="return CheckValidation(this);">Save</button>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900