Skip to content

Instantly share code, notes, and snippets.

@fleeting
Created April 27, 2010 16:21
Show Gist options
  • Save fleeting/380934 to your computer and use it in GitHub Desktop.
Save fleeting/380934 to your computer and use it in GitHub Desktop.
$('#employmentForm').submit(function(){
error = 0;
$('.formErrors').empty();
$('.requiredField').each(function() {
if ($(this).attr("type") == "text") {
if ($(this).val() == '') {
fieldName = $(this).attr("name").split('|');
$('.formErrors').append('<li><strong>'+$(this).parent().attr("name")+'</strong>: '+fieldName[2].slice(0,-1)+' is required.</li>');
error++;
}
} else if ($(this).attr("type") == "checkbox") {
if ($(this).is(':not(:checked)')) {
fieldName = $(this).attr("name").split('|');
$('.formErrors').append('<li><strong>'+$(this).parent().attr("name")+'</strong>: '+fieldName[2].slice(0,-1)+' is required.</li>');
error++;
}
}
});
if(error == 0) {
return true;
} else {
$.scrollTo('header', 1000);
$('.formErrors').fadeIn("slow");
return false;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment