I am working on validation rules and I would like to use pure javascript. I would also like to use JQuery validator. So here is my problem. I am typing different fields of a form and I would like to detect the invalidation at the moment the client is typing (dynamically). I found a solution but that's not the required result. So I would not want to use the alert function. Here is my code :
$('#name').keyup(function(key)
{
if (this.value.length >= 2 || this.value == '')
{
alert('my message'); // This works but it not what I want to do.
// I want to have a message after my field with the error message.
$('#name').after('<span class="error"> my message</span>');
//This is what I try also but it repeat the message many times.
document.getElementById("name").innerHTML = "my message";
// I tried this but I didn't see anything in my browser.
}
});
So what I want to do of example in this function is to print a message telling me the field is empty and disappear once it's not. Any Suggestions?