Monday, 11 January 2016

Java script 6

JavaScript Form Validation

 

If the form submitted is Empty,the function should return alert message and prevent from submitting the form.

JavaScript Example

function validateForm()
 {
    var x = document.forms["myForm"]["fname"].value;
    if (x == null || x == " ")
 {
        alert("Name must be filled out");
        return false;
    }
}

 After filling out the fname the form will be submitted. 

 

Typical validation tasks are:
  • has the user filled in all required fields?
  • has the user entered a valid date?
  • has the user entered text in a numeric field?

End of the basic Java script.

No comments:

Post a Comment