views:

400

answers:

2

Hey guys,

Here is what I am currently using to attempt to validate a form. When I press submit with no values entered into the form, I get the error messages for each of the inputs as expected. However, no matter what I put in newpassword2 or newemail2 they never 'pass' validation. I've tried everything from copy and paste to making them one letter each to no success. Perhaps I am not using the equalTo attribute correctly...

I've also verified that all the names of the selectors agree with the input id's on the form. Also, all of the inputs are contained within the form, so there aren't any outside of the form tags (I read that was an issue with someone else).

$(document).ready(function() { 
    $("#account_data").validate({ 
        rules: { 
            newpassword1: { required: true }, 
            newpassword2: { equalTo: "#newpassword1" },
            newemail1: { required: true, email: true },
            newemail2: { equalTo: "#newemail1" }
        }
    }); 
});

Any help would be extremely appreciated!

THANK YOU!!!

-Tom-

+2  A: 

@Tom try

        newpassword1: { required: true }, 
        newpassword2: { required: true,equalTo: "#newpassword1"},
        newemail1: { required: true, email: true },
        newemail2: { required: true,email: true ,equalTo: "#newemail1" }

or use the latest version of validation plugin

Now rules have added with password being required set to true and the second condition is for password_again set to required true and it has to “equalTo” the input field with id of password. With these conditions set, we are able to achieve what we are wanting. Do not forget to check the demo of the post to see how it works. For more documentation and resource on this plugin visit jQuery Validation Plugin

check this online demo

Pandiya Chendur
@PandiyaYou know what? I got it to work with exactly the same code I posted in my original post. All I changed was using both an id AND name for the form inputs. I don't know if this is necessary, though, as name does not validate in (X)HTML Strict if I recall correctly.Regardless, the validation plugin is working fine, and my question is now obsolete...sorry for wasting your time!BTW, I added in the other attributes that you suggested and it still worked just fine!THANK YOU FOR YOUR HELP!!!-Tom-
Tom Winchester
A: 

Thanks Tom, Your post really helped me. There is a bug in the validate.plugin because of which it did not work without providing the id="fieldname" for both matching fields.

Thanks a lot for your help.

Regards, Haider Abbas

Haider Abbas