2

I am creating 10 forms dynamically

for example form would be like this

<form name="form_example" action="sample.php">
Name:<input type="text" name="name" id="name"><br />
Email:<input type="text" name="email" id="email"><br />
<input type="submit" name="save" value="Save Details">
</form>

In this way 10 similar forms in same screen and i had written only one jquery.validate function to handle all these forms dynamically.

$("form[name='form_example']").validate();

Thus the above validation code doesnt takes care of all the form validation dynamically. I dont know how to handle multiple similar form validation using single validate function.

Help me. Thanks in Advance.

1 Answer 1

7

Give all your forms the same class, lets say validation. Then you could do something like

$('.validation').each( function(){
    $(this).validate();
});

Now it validates all the fields when someone clicks on submit.

But rather check the manual cause everything is explained there.

Sign up to request clarification or add additional context in comments.

3 Comments

s it works but once error displays in any one of the form makes. other particular form not submitted. i had used $("form[name='form_example']").resetForm() but if there is error in other form then particular form in which user enters a data cant be submitted...
What this does is validating each form, if one fails none of them are submitted. If your just want multiple forms which all contain the same fields that on submit will validate one form (the submitted form) you can do just $('.validation').validate();
I found $('form').validate() creates one validation for all forms, where $('form').each( function(){$(this).validate();}); create separate validations for each form. This is the reverse of what Tim is saying. to my surprise.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.