I wrote this code for validating form:
$('form').submit(function() {
$.each($(this).find('.required'), function(i,d){
var lName = '#'+$(d).attr('for');
if (!$(lName).val()) {
$('html, body').animate({ scrollTop: $(d).offset().top }, 'slow');
$(d).css({'color': '#ff0954'});
if ($(lName).attr('class') == 'ckeditor') {
}else{
for(i=0;i<3;i++) {
$(lName).fadeTo('fast', 0.5).fadeTo('fast', 1.0);
}
}
return false;
}
});
});
my code will search in label tags with reqiured class name and will validate field.
Every thing seems to be ok, but I have some problems:
- I use
return false;when field have problem, but the form will be submit . - I cannot
focusonckeditorclass - I cannot validate
radio,checkboxandselecttags
Thanks to @Sparky , I will use jQuery Validation Plugin instance of I wrote from scratch :
http://docs.jquery.com/Plugins/Validation