JQuery validation plugin showErrors () function

The following script works fine:

$("#regform").validate().showErrors({"username":"message"}); 

After I changed the script to the bottom, it does not work.

 var name = "username"; $("#regform").validate().showErrors({name:"message"}); 

I need to pass the field name of the variable. Does anyone know how this problem can be solved?

+7
jquery jquery-plugins
source share
1 answer

You must build an object literal and use the access operator >:

 var name = "username", obj = {}; obj[name] = "message"; $("#regform").validate().showErrors(obj); 
+13
source share

All Articles