Hi,
I've been writing a site, with many forms, and wanted to validate the forms with jQuery, before submitting the form. So, I've been using this: http://docs.jquery.com/Plugins/Validation plugin to do the validation. It works, if I call the script on the initial page load; for example:
Code:
<form> random stuff </form>
<script>
$("form").validate();
</script>
However, there are some pages with multiple forms, but only one form needs to be validated, so I wrote the following script:
Code:
$(document).ready(function(){
$("form").click(function() {
//check to see if a form has been validated on the page already, or not:
if(!formValidation)
{
//if mulitple forms, the id of the form will have been set, and we can validate a single form:
if(this.id != "")
$("form#"+this.id).validate();
//if no id has been set on the form, validate every form on the page:
else
$("form").validate();
//stop another form from being validated, when its clicked on.
formValidation = true;
}
});
});
However, the form validation does not occur; the page will submit regardless of the state of the form.
Anyone have any ideas? Any help is very much appreciated.
Thanks a lot,
Scott
|