Form Validation

Home

So you want to validate a form. Usually this just involves checking that required fields have been entered. Put this function in your header JavaScript, copy'n'paste the "if" as many times as you need, and edit the field names and messages:

function validate(form) {
  if (form.Surname.value == "") {
    alert('"Surname" is a required field. Please enter your surname and try again.')
    form.Surname.focus()
    return false
  }
  return true
}

Now add the following attribute to your form element:

onSubmit="return validate(this)"