Skip to content

Instantly share code, notes, and snippets.

@elango
Forked from dawsontoth/validateForm.js
Created February 5, 2011 00:23
Show Gist options
  • Save elango/812059 to your computer and use it in GitHub Desktop.
Save elango/812059 to your computer and use it in GitHub Desktop.
function validateForm() {
var formIsValid = true;
function enforceTextFieldMinLength(field, minLength) {
if (!field.value || field.value.length < minLength) {
formIsValid = false;
}
}
function enforceLabelHasText(label) {
if (!label.text) {
formIsValid = false;
}
}
// check first name
enforceTextFieldMinLength(tfFirstName, 5);
// check last name
enforceTextFieldMinLength(tfLastName, 5);
// check label connected to gender drop down
enforceLabelHasText(lGender);
if (formIsValid) {
alert('Form is valid!');
}
else {
alert('Form is invalid...');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment