Hi, this is my script: <form id="frm1"><fieldset> <ul> <li> <label for="name">Name:</label> <input type="text" name="name" /> </li> <li> <label for="email">Email:</label> <input type="text" name="email" /> </li> <li> <label for="one">one:</label> <input type="text" name="one" /> </li> <div id="results"><div> <li> <input type="submit" value="submit" /> </li> </ul> </fieldset> </form> jQuery(document).ready(function($){ $("#frm1").validate({ debug: false, rules: { name: "required", email: { required: true, email: true } }, messages: { name: "Please let us know who you are.", email: "A valid email will help us get in touch with you.", }, }); }); The script works fine, but I would like to change something. I would like this: <input type="text" name="name" /> to change into this: <input type="text" id="name" /> But when I do this, the validation script does not work. Is there a way to change this? Thank you!
If your validation is looking for the element by name you have to change it to look for the element by ID.
That depends on what you're using to validate the form, the jQuery validator plugin or something else. The plugin should work on ids as it is (I've never used it, but the documentation seems to indicate that it'll validate the entire form).
Why can't you just do this: [COLOR=#111111]<input type="text" [/COLOR]name="name" id="name" /> Code (markup): And have both the name AND id in there?
You can, but if you need only one of them you're just increasing the amount of cruft the user has to download. Use the one that the code needs. (There's almost never any reason for the code to need both unless it's very badly written.)
Excuse me? the "name"-attribute is REQUIRED for either post or get-functionality to work (we're not talking javascript here) - tha ID is an identifier, albeit it's not really NEEDED anymore for anything, it's still a different attribute than "name", and those two (apart from in javascript, and to some extent CSS) are NOT interchangable. If, for instance, he want to validate form values using jQuery, he can use either, same if he submits the form via jQuery ($.post or whatever) - however, if the user have turned OFF javascript, for instance, he would want a reliable fall-back, and hence, should use the "name"-attribute. If you remove the name-attribute, the HTML is no longer valid, btw.