Skip to content

Instantly share code, notes, and snippets.

@dawsontoth
Created February 4, 2011 23:37
Show Gist options
  • Select an option

  • Save dawsontoth/812022 to your computer and use it in GitHub Desktop.

Select an option

Save dawsontoth/812022 to your computer and use it in GitHub Desktop.

Revisions

  1. dawsontoth created this gist Feb 4, 2011.
    25 changes: 25 additions & 0 deletions validateForm.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    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...');
    }
    }