You would have to pass in an anonymous function in the message parameter, because you just cannot pass msg from the result of the previous anonymous function to the next parameter (as msg, in your context, only exists within that particular anonymous function scope).
$.validator.addMethod("customMethod", function(value, element) {
// Do your usual stuff here.
}, function (params, element) {
var msg;
if(cond1){
msg = "msg1";
}
else if(cond2){
msg = "msg2";
}
else if(cond3){
msg = "msg3";
}
return msg;
});
However, you could just declare msg in the global scope like this:
var msg;
var dynamicErrorMsg = function () { return msg; }
$.validator.addMethod("customMethod", function(value, element) {
if(cond1){
msg = "msg1";
}
else if(cond2){
msg = "msg2";
}
else if(cond3){
msg = "msg3";
}
}, dynamicErrorMsg);
And this would work as well.