The following script works fine:
$("#regform").validate().showErrors({"username":"message"});
After I changed the script to the below one, it doesn't work.
var name = "username";
$("#regform").validate().showErrors({name:"message"});
I need to pass the field name by a variable. Anyone knows how this problem can be solved?
You should build an object literal and use the bracket notation member access operator:
var name = "username",
obj = {};
obj[name] = "message";
$("#regform").validate().showErrors(obj);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With