i want to know that can we create two instance of same validator method in one js??
now let me tell u what i want exact
i have two pages basic.php
another is contact.php
having forms, name is basicForm
and contactForm
respectively , now i want to include one extrenal JS (validForm.js
) file where i want to put both forms validator definations, but unable to succeed.
like
validForm.js
var validator = jQuery("#basicForm").validate({
some rules...
});
var validator = jQuery("#contactForm").validate({
other rules...
});
so i want to know
- may i invoke two instance of var validator in same js? or
- d开发者_Python百科o i have to use different js( having validator method) for different pages?
Name those validators according to the form they're supposed to validate
var basicFormValidator = jQuery("#basicForm").validate({
some rules...
});
var contactFormValidator = jQuery("#contactForm").validate({
other rules...
});
I suggest you to do not create separate js file for each form validation (like your: validForm.js), as number of external js call will decrease performance of your page in terms of speed.
So if possible make all validation separate for each page. Write the script on each page.
If you have lots of custom validation, then you can add them to jquery.validate.js
file.
精彩评论