<html><head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"><script type="text/javascript">
	function validate(inputItem)
	{
	/*
	*************Instructions*******************
	Radios and checks get onclicks
	Selects and file inputs get onchanges
	textboxes and textareas get onblur
	
	All  required elements pass themselves to the validate function
	All required elements will have a corresponding element such as a p,span,label for error output. These elements will have an ID based off the element's name i.e. An element named "fname" will need a corresponding element with an ID of "fname_error". For instances where an array checkgroup is used
	the corresponding element needs the name minus the brackets.
	
	Fill in the formname to validate
	Fill in the array of required element names in order of how they appear in the form.
	
	Never have to code a validation script ever again
	
	Questions, comments, and mama jokes ajeisan@yahoo.com
	*/
	var formToVal = "myform"; // Your form name
	var tocheck = ['fname','lname','email','file','mydrop','mydrop2','mydrop3','radgrp','radgrp2','radgrp3','Chkgrp1[]','Chkgrp2[]','Chkgrp3','comments']; //list of required elements in order in which they appear
	var errors = 0;
	
		for(x=0; x<=tocheck.length-1;x++)
			{
			 document.getElementById(tocheck[x].replace( "[]", "")+"_error").innerHTML = "";
			}
	parentLoop: for(i=0;i<=tocheck.length-1;i++)
	{
	ChkCount=0
		if(document.forms[formToVal][tocheck[i]].tagName=='SELECT')
		{
				if(document.forms[formToVal][tocheck[i]].value == '')
				{
				errors++;
				document.getElementById(tocheck[i]+"_error").innerHTML = "This field is required";
				}
				if(document.forms[formToVal][tocheck[i]].name == inputItem.name)
						{
						break parentLoop;
						}
		}
		else if(document.forms[formToVal][tocheck[i]].length>0)
		{
		checkloop: for(z=0;z<=document.forms[formToVal][tocheck[i]].length-1;z++)
				{
				if(document.forms[formToVal][tocheck[i]][z].checked==true)
					{
						if(document.forms[formToVal][tocheck[i]][z].value == inputItem.value)
						{
						break parentLoop;
						}
						ChkCount++
					}
					else if(z==document.forms[formToVal][tocheck[i]].length-1)
					{
						if(ChkCount < 1)
						{
						errors++;
						document.getElementById(tocheck[i].replace( "[]", "" )+"_error").innerHTML = "This field is required";
						}
					}
				}
		}
		else if(document.forms[formToVal][tocheck[i]].type=="radio" || document.forms[formToVal][tocheck[i]].type=="checkbox")
		{
			if(document.forms[formToVal][tocheck[i]].checked==false)
			{
			errors++;
			document.getElementById(tocheck[i]+"_error").innerHTML = "This field is required";
			}						
			if(document.forms[formToVal][tocheck[i]].name == inputItem.name)
					{
						break parentLoop;
					}
		}
		else
		{
			if(document.forms[formToVal][tocheck[i]].value == '')
				{
				errors++;
				document.getElementById(tocheck[i]+"_error").innerHTML = "This field is required";
				}						
				if(document.forms[formToVal][tocheck[i]].name == inputItem.name)
						{
							break parentLoop;
						}
		}
	}
		if(inputItem.name=="submit" && errors < 1)
		{
			alert('This is replaced with submit');//replace this with submit actions
		}
	}
	</script>

</head><body><form name="myform" action="weee.html" method="post">
First Name:<input name="fname" onblur="validate(this)" type="text"><label
 class="error" id="fname_error"></label><br>
Last Name:<input name="lname" onblur="validate(this)" type="text"><label
 class="error" id="lname_error"></label><br>
Email:<input name="email" onblur="validate(this)" type="text"><label 
class="error" id="email_error"></label><br>
File:<input name="file" onchange="validate(this)" type="file"><label 
class="error" id="file_error"></label><br>
<select name="mydrop" onchange="validate(this)">
	<option selected="selected" value="">Please Select One</option>
	<option value="opt1">Opt1</option>
	<option value="opt2">Opt2</option>
	<option value="opt3">Opt3</option>
</select><label class="error" id="mydrop_error"></label> <br><br>

<select name="mydrop2" onchange="validate(this)">
	<option selected="selected" value="">Please Select One</option>
	<option value="opt12">Opt12</option>
	<option value="opt22">Opt22</option>
	<option value="opt32">Opt32</option>
</select><label class="error" id="mydrop2_error"></label><br><br>

<select name="mydrop3" multiple="multiple" onchange="validate(this)">
	<option selected="selected" value="">Please Select One</option>
	<option value="opt12">Opt12</option>
	<option value="opt22">Opt22</option>
	<option value="opt32">Opt32</option>
</select><label class="error" id="mydrop3_error"></label><br><br>


<br>
<label class="error" id="radgrp_error"></label><br>
<input name="radgrp" value="rad1" onclick="validate(this)" type="radio">
 Rad1 <br>
<input name="radgrp" value="rad2" onclick="validate(this)" type="radio">
 Rad2 <br>
<input name="radgrp" value="rad3" onclick="validate(this)" type="radio">
 Rad3 <br><br>


<label class="error" id="radgrp2_error"></label><br>
<input name="radgrp2" value="rad1" onclick="validate(this)" type="radio">
 Rad1 <br>
<input name="radgrp2" value="rad2" onclick="validate(this)" type="radio">
 Rad2 <br>
<input name="radgrp2" value="rad3" onclick="validate(this)" type="radio">
 Rad3 <br><br>

 <label class="error" id="radgrp3_error"></label><br>
<input name="radgrp3" value="rad1" onclick="validate(this)" type="radio">
 Rad1 <br>
<br><br>
 
<label class="error" id="Chkgrp1_error"></label><br>
<input name="Chkgrp1[]" value="Chk1" id="Chk1" onclick="validate(this)" 
type="checkbox"> Chk11 <br>
<input name="Chkgrp1[]" value="Chk2" id="Chk2" onclick="validate(this)" 
type="checkbox"> Chk12 <br>
<input name="Chkgrp1[]" value="Chk3" id="Chk3" onclick="validate(this)" 
type="checkbox"> Chk13 <br><br>

<label class="error" id="Chkgrp2_error"></label><br>
<input name="Chkgrp2[]" value="Chk1" id="Chk1" onclick="validate(this)" 
type="checkbox"> Chk21 <br>
<input name="Chkgrp2[]" value="Chk2" id="Chk2" onclick="validate(this)" 
type="checkbox"> Chk22 <br>
<input name="Chkgrp2[]" value="Chk3" id="Chk3" onclick="validate(this)" 
type="checkbox"> Chk23 <br><br>

<label class="error" id="Chkgrp3_error"></label><br>
<input name="Chkgrp3" value="Chk1" id="Chk1" onclick="validate(this)" 
type="checkbox"> Chk31 <br>
<br><br>

Comments:<br><textarea name="comments" onblur="validate(this)"></textarea><label
 class="error" id="comments_error"></label><br>
<input name="submit" value="submit" onclick="validate(this);" 
type="button">
</form></body></html>