I am new to JS, I have a problem with JQUERY semantics.
I have a function written to check the contents of a cell.
Problem: the function is launched only when the cell loses focus, if I click "Submit", an error first appears, then it launches the function.
I want the function to run even when I'm inside the cell. How to do it?
Initiated as follows:
$(".user_id").blur(function(){ validateUserId($('.user_id')); });
Function:
function validateUserId(reference) {
if ( 5 == $(reference).val().length ) {
$.get('index.php?user=' + $(reference).val(), function(data) {
if ( "error" == data ) {
$(reference).parent().parent().addClass('error');
alert('error');
} else {
$(reference).parent().parent().removeClass('error');
$(reference).addClass('valid');
$(reference).parent().parent().addClass('success');
}
});
} else {
alert('short');
$(reference).parent().parent().addClass('error');
}
}
source
share