ITSE 1411 Beginning Web
JS Form Validation Chapter 5 Discussion
Discussion
  1. Form Validation using onsubmit and onreset event handlers
    • The submit button, when pressed, triggers the onsubmit event handler.
    • The onsubmit event handler is written inside the form tag.
    • The onsubmit event handler is often used to validate the form data.
    • The reset button, when pressed, triggers the onreset event handler.
    • The onreset event handler is also written inside the form tag.
    • The onreset event handler is often used to confirm that the form is to be reset.
    • The onsubmit and onreset event handlers often call functions to perform the work needed to validate or confirm that a form is to be reset. The function called by the onsubmit event handler returns true when the validation is completed and all elements are valid and a false when any element is not valid. The onreset event handler returns a true when the reset is confirmed and a false when the reset is cancelled.
  2. Validating Text and Password Boxes
    • Test to see that text boxes and password boxes using the if statement. For numeric fields test with isNaN() method. Return a true when all boxes validate. Return a false when any box does not validate. It is helpful to use an alert box to show why something does not validate.
  3. Validating Radio Buttons
    • JavaScript creates an array of elements that share the same name, so that a single name=value pair will be submitted when the form is submitted. The checked property returns a true is selected and a false if not selected.
  4. Validating Check Boxes
    • You may select one or more check boxes in a group. The checked property returns a true when a box is selected and a false when a box is not selected.
  5. Validating Selection Lists
    • If no selection has been made in a selection list, the selectedIndex property contains a value of -1.