[validate] Random Success Message
I am using the jQuery Validate plugin and trying to generate random success messages. Eveything is working with this code.
- var messages = ["Good!", "Great!", "Awesome!", "Super!", "Nice!"];
function successMessage() {
return messages[Math.floor(Math.random() * messages.length)];
}
and then:
- success: function(label) {
label.addClass("valid").text(successMessage());
}
The problem is that the success message is being called on keyup so it is generating a success message with each keypress or when you click onto then off of a field. I tried this but it didn't work
- success: function(label) {
if(!$(this).hasClass("valid")){
label.addClass("valid").text(successMessage());
}
Any help would be great