It seems to be simple logic thing, but some how I cannot figure it out. I am behind this more than 2 hours and nothing seems to be working.. I am doing a form validation. On submit of the form, I check if the fields are empty or not. If empty, I add a class to the field so it becomes red in color and then create a new div and display a error message. I am having couple of issues with this. I am testing in IE8 and addClass is not working in that. Below is the code snippet
var first = true;
if(first == true){
$('#submit_form .required').filter(':visible').each(function() {
var input = $(this);
if($(this).is(':empty')){
$(this).css("border","1px solid #FF0004");
//$(this).addClass("highlight");
$(this).after('<div class="error_text">Required</div>');
first = false;
return false;
}else{
return true;
}
});
}
else{
$('#submit_form .required').filter(':visible').each(function() {
var input = $(this);
if($(this).is(':empty')){
$(this).css("border","1px solid #FF0004");
//$(this).addClass("highlight");
//I ned to remove the Required text here or else it will get added twice.
$(this).after('');
//Add the text here
$(this).after('<div class="error_text">Required</div>');
return false;
}else{
return true;
}
});
}
So when the user clicks the submit button for first time first = true, it validates and which ever field is empty, it will display that red border and the text as well. This is working fine. Now when the user fills in some fields and again enter submit, there are some more mandatory fields that are not filled in. So now I want the filled fields to be remove the border and the Required text and then display red and Required for those that are empty now. I tried so many things and I am sick with this. Somehow I am not getting a right logic for this. Can some body out there help me in this? I don't want to use validate plugin.
return = false;correct code isreturn false;orreturn true;...return = false;this line means you are assigning false value to return variable.$(this)to the variableinputwhy do you keep using$(this)?