I want to validate some asp.net textboxes with the jQuery Validation plugin found at http://docs.jquery.com/Plugins/Validation, but it appears that the elements must be between a form tag. If I have just a couple elements, I would hardly call that a form, so I would rather not have them wrapped inside a form element. Is there a way around this? Also, if I have two buttons on the form, a cancel and a submit button and I want the form only to validate when the submit button is clicked, but not the cancel button, how is this accomplished?
¶jQuery Validation PluginThe plugin comes bundled with a useful set of validation methods, including URL and email validation, while providing an API to write your own methods. All bundled methods come with default error messages in english and translations into 37 other languages.
UnobtrusiveJavaScriptEnabled" property value back to false and create a new file in "Scripts" folder and name it "script-custom-validator. js". Add the Jquery validator code in it as shown below i.e. The above piece of code attaches my account register form with jQuery form validator by using form ID.
JQuery is a light, “write less, do more”, Javascript library. The purpose of JQuery is to make it much easier to use JavaScript on your website. It simplifies HTML document traversing, event handling, animating and AJAX interactions for rapid web development.
I have just a couple elements, I would hardly call that a form, so I would rather not have them wrapped inside a form element.
If the elements are not within a form tag, then it is not a valid HTML document, so behavior within script might get wonky depending on how the browser deals with the malformed HTML.
Most browsers will create a form implicitly, but now you have no control over the form's behavior. The defaults are usually be a post action form targeted at the requested page's URL.
The problem is, you probably have no idea what selector to use in the JQuery to get a reference to the form... but I suppose $("form")
would do the trick.
validate when the submit button is clicked, but not the cancel button
The plug-in intercepts and runs on the submit event of a form. Generally cancel buttons are html input elements with the type attribute set to "reset":
<input type="reset" value="cancel" />
A reset type button will not cause the form to submit, and this will not trigger the validation.
If you use another button type, make sure the onclick even returns false. This cancels the form's submit action but still allows you to run javasctipt of your own when the button is clicked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With