Validate Form Data Before Submit

[Total: 0    Average: 0/5]

This shows another method to verify text boxes input and then put the focus into missing data boxes.

Head Code:

<script language="javascript"> 
function verify(form) { 
  for (i=0; i<form.elements.length; i++ ) { 
    if ((form.elements[i].type=="text" || 
         form.elements[i].type=="textarea") &&
		form.elements[i].value == "") 
	  // having this alert not commented out causes the focus to not work correctly...
      //alert("Please fill out all fields.");
  // if all else is validated - then validiate the email...

function everify(form) { 
  if ( == "" ||'@') == -1 ||'.') == -1 ||<6) { 
	// same for this alert and the focus issue.
    //alert("Not a valid e-mail address!");;
  // uncomment this to submit the form when all validated.
  // form.submit();

Body Code:

<table  cellpadding=2 cellspacing=2 ><tbody  valign="top"> 
<tr><td>First Name<td><input type=text name="first" size=26></tr> 
<tr><td>Last Name<td><input type=text name="last"size=26></tr> 
<tr><td>Mailing Address<td><textarea name="address" rows=3 cols=20 ></textarea></tr> 

<tr><td>Day Time No.<td><input type=text  name="day" size=26></tr> 
<tr><td>Evening No.<td><input type=text name="evening" size=26></tr> 
<tr><td>Email Address<td><input type=text name="email" size=26></tr> 


<input type="button" value="Submit" onClick="verify(this.form);"> 
<input type="Reset"  value="Reset"> 

Times Viewed: 5

Leave a Reply

Your email address will not be published. Required fields are marked *