Click here to Skip to main content
11,790,816 members (53,740 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C#4.0 MVC3

$('#btnSiteSave').click(function (e) {  
        var password=$('input[id$=password]').val();
        var confirmpassword=$('input[id$=cpassword]').val();
          $("#cpassword").rules("add", {
          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
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?
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
Please Sign up or sign in to vote.

Solution 1

You can try like this

<script type="text/javascript" src=""></script>
<script type="text/javascript">
function CheckValidation() {
     $('#Error_pspan').html("Password and Confirm Password are not matched");
                 return false;

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

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

  Print Answers RSS
0 OriginalGriff 385
1 ppolymorphe 339
2 Richard MacCutchan 118
3 Maciej Los 70
4 George Swan 70
0 OriginalGriff 1,154
1 Maciej Los 825
2 KrunalRohit 686
3 ppolymorphe 660
4 CPallini 621

Advertise | Privacy | Mobile
Web03 | 2.8.1509028.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