Validate Form Data Onsubmit

[Total: 0    Average: 0/5]

This example shows how to have a simple form validated before submitting.

Head Code:

<script language="javascript"> 

<!-- Begin 
function check(which) { 
  var p=true; 
  if (document.images) { 
    for (i=0;i<which.length;i++) { 
      var tempobj=which.elements[i]; 
      if (,8)=="") { 
        if (((tempobj.type=="text" ||
             tempobj.value=='') ||
             tempobj.selectedIndex==0)) { 
  if (!p) {,30).toUpperCase(); 
    alert("Please make sure the "+shortFieldName+" field was properly completed."); 
    return false; 
    return true; 
//  End --> 


Body Code:

<form onSubmit="return check(this)"> 

<input type="text" > 
<input type="text" name="email"> 
<select name="hobby"> 
<option selected>Pick an option! 
<textarea name="comments"></textarea> 
<input type=submit value="Submit"> 

Times Viewed: 0

Leave a Reply

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