开发者

can we put two form validator method combined in one external JS?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜