HTML CSS JavaScript jQuery AJAX ASP PHP SQL tutorials, examples for web building ,author kapil kumar: Form validation with javascript

Friday 9 May 2014

Form validation with javascript

Required Fields

Sometimes we need to restrict the user for entering values which is not required.

This function checks if a field has been left empty. If the field is blank, an alert box alerts a message, the function returns false, and the form will not be submitted:

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



Written by

 

No comments:

Post a Comment