Click here to Skip to main content
11,640,521 members (60,014 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0 MVC3
Hi,

$('#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 15-Aug-12 23:22pm
v2
Comments
Sergey Alexandrovich Kryukov at 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
ryanb31 at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You can try like this

<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>


<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>
  Permalink  

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

  Print Answers RSS
0 Mika Wendelius 370
1 OriginalGriff 205
2 Afzaal Ahmad Zeeshan 130
3 CPallini 125
4 DamithSL 105
0 Mika Wendelius 370
1 OriginalGriff 205
2 CPallini 125
3 DamithSL 105
4 Afzaal Ahmad Zeeshan 70


Advertise | Privacy | Mobile
Web04 | 2.8.150731.1 | Last Updated 22 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100