简体   繁体   中英

Password confirm validation fails

HTML code:

<div id="form_pwd">          
<form method="POST" action="google.com" id="pwdChange">
    <table>
        <tr>
            <td width="175px"><label for="newPwd">Enter your password</label></td>                
            <td><input type="password" name="newPwd" id="newPwd" size="35"/></td>
        </tr>
        <tr>
            <td><label for="newPwd_">Re-enter your password</label></td>
            <td><input type="password" name="newPwd_" id="newPwd_" size="35"/></td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td><input type="submit" value="Save Password" /></td>
        </tr>
    </table>

</form>
</div>

jQuery code:

    $(document).ready(function()
{
    $("#form_pwd").validate(
    {
    rules:
    {
        newPwd: "required",
        newPwd_:
        {
        equalTo: "#newPwd"
        }
    }
    }
    );
}
);

I use the above source to validate my input passwords but there is nothing being shown next to the text boxes, would someone please have a look and help me spot it ? i already include

  <script type="text/javascript" src="http://jzaefferer.github.com/jquery-validation/jquery.validate.js"></script>
<script type="text/javascript">
jQuery.validator.setDefaults({
    debug: true,
    success: "valid"
});
</script>

at the top of the file. :(

[ Update ]Ok, the demo is here http://jsfiddle.net/Z9JmB/2/

I hope someone could help me out with this tiny problem. Thank you sooo much .

This works fine, but you're targeting the div outside of the form. You need to change the target element from:

$("#form_pwd")

to:

$("#pwdChange")

This will target your form.

Also, in your JS fiddle, you need to include your validation js file. I updated the jsfiddle to include the validation plugin your using, it all works 100% correctl, please have a look:

http://jsfiddle.net/Z9JmB/5/

This looks fine. Make sure your password input has id="newPwd" or post more code. Maybe setup a jsfiddle.net

Also see manual http://docs.jquery.com/Plugins/Validation/Methods/equalTo#other

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM