Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
163
rated 0 times [  164] [ 1]  / answers: 1 / hits: 55690  / 11 Years ago, sat, july 20, 2013, 12:00:00

I validated some fields in my form.. But i have some issues..If without enter fields it shows error message.. If fill out the field still error message is showing..



How to put that ?



My code



 $(#Name).focus();
$(#Name).blur(function(){
var name=$('#Name').val();
if(name.length == 0){
$('#Name').after('<div class=red>Name is Required</div>');
}
else {
return true;
}
});

$(#Address).blur(function(){
var address=$('#Address').val();
if(address.length == 0){
$('#Address').after('<div class=red>Address is Required</div>');
return false;
}
else {
return true;
}
});


can anyone help me please?????


More From » jquery

 Answers
6

You should remove this labels after that user input some data



$(#Name).focus();
$(#Name).blur(function(){
var name=$('#Name').val();
if(name.length == 0){
$('#Name').after('<div class=red>Name is Required</div>');
}
else {
$('#Name').next(.red).remove(); // *** this line have been added ***
return true;
}
});

$(#Address).blur(function(){
var address=$('#Address').val();
if(address.length == 0){
$('#Address').after('<div class=red>Address is Required</div>');
return false;
}
else {
$('#Address').next(.red).remove(); // *** this line have been added ***
return true;
}
});


jsfiddle: DEMO


[#76861] Thursday, July 18, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
charisma

Total Points: 1
Total Questions: 99
Total Answers: 117

Location: Thailand
Member since Thu, Apr 22, 2021
3 Years ago
;