javascript - how to run a function with parameters -


i have function validates forms (for old browsers). function works fine except have pass parameters every time call function, in fact specified default parameters in 'config'.

so logic, if called function as: validateme(); should run validateme({requiredclass: '.required', verifiedclass: 'invalid'});

but unfortunately calling function without parameters doesn't work correctly ( in case form triggers submission event) (it doesn't reach return false).

so missing in code run function default settings??

function validateme(vform, settings) {      var vform,      //form name or id         config = {             'requiredclass': '.required',              'verifiedclass': 'invalid'         };     if (settings) {         $.extend(config, settings);     }      $(vform).on('submit', function(){          var inputs =  $(this).find(config.requiredclass),              required = [];         (i=0; < inputs.length; i++) {              if (inputs[i] != null) {                 if ($(inputs[i]).val().replace(/^\s+|\s+$/g, '') == '') {                     required.push($(inputs[i]).index());                 }             }         }          if (required.length > 0) {             $(this).find('input').removeclass(config.verifiedclass);             for(n=0;n<required.length;n++) {                 $(inputs[n]).addclass(config.verifiedclass);             }             return false;            }      }); } 

any help?

thanks.

function validateme(vform, settings) { this.vform = vform || 'default', this.setting = 'whatever', this.private = '' } var newinstance = new validateme(); 

now have instance of it, can define go.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -