0

Hi,
I have the following J.s and Html code:

//function for mandatory 


function validatebox(field,alerttxt)
{
with (field)
  	
	{
  	if (value==null||value==""||value=="Please Choose")
    		{
   		alert(alerttxt);
    		return false;
   		 }
  	
	else
    		{
    		return true;
    		}
 	 }
}


function validate_form(thisform)
{
		with (thisform)
  		{
  			if (validatebox(Givname,"Given name must be filled out!")==false)
  
			{
			Givname.focus();
			return false;
			}
			if(validatebox(FamName,"Family Name Must be Filled Out!")==false)
			{
			FamName.focus();
			return false;
			}
			if(validatebox(Ext,"Phone Extension Must be Filled Out!")==false)
			{
			Ext.focus();
			return false;
			}
			if(validatebox(Mail,"Email Must be Filled Out!")==false)
			{
			Ext.focus();
			return false;
			}
			if (validatebox(Ext,"Extension must be filled out!")==false)
  
			{
			Ext.focus();
			return false;
			}
			if (validatebox(EmpID,"Employee ID must be filled out!")==false)
  
			{
			EmpID.focus();
			return false;
			}

			if (validatebox(jobTitles,"Given name must be filled out!")==false)
  
			{
			jobTitiles.focus();
			return false;
			}

			if (validatebox(Sup,"Supervisors name must be filled out!")==false)
  
			{
			Sup.focus();
			return false;
			}
			if (validatebox(fromDate,"From Date must be filled out!")==false)
  
			{
			fromDate.focus();
			return false;
			}
			if (validatebox(toDate,"To Date must be filled out!")==false)
  
			{
			toDate.focus();
			return false;
			}


  		}

}



//Function to validate text box

function ValidateText() 
{

                var patterns = new RegExp("^[A-Za-z -]*$");    /* Regular expression to allow only space,hyphen,alpha */

                var name = document.getElementById('Givname').value;   /* Read all values one by one in variable */
                var course = document.getElementById('FamName').value;
		var super=document.getElementById('Sup').value;
	
	
                if (!patterns .test(name)) 
		{
                    window.alert("Only alphabets spaces and hyphens allowed in the Given Name Box.");                
                    return false;
                }

                if (!patterns .test(course ))
		 {
                    window.alert("Only alphabets spaces and hyphens allowed in the Family Name Box.");                
                    return false;
                }

	   	if (!patterns .test(super ))
		 {
                    window.alert("Only alphabets spaces and hyphens allowed in the Supervisors Name Box.");                
                    return false;
                }
}




//Function to validate Phone Extension

function validateNum()
{
		var pattern=new RegExp("^[0-9]*$");
		
		var num=document.getElementById('Ext').value;
		var num2=document.getElementById('EmpID').value;
		
		if(!pattern.test(num))
		{
                    window.alert("Only Numbers are allowed in the Extension Text box!");                
                    return false;
                }

		if(!pattern.test(num2))
		{
		window.alert("Only numbers are allowed in the Employee ID box!");
		return false;
		}

}






//Function to Validate DATE



function checkdate(objName) 
{
var datefield = objName;
	if (chkdate(objName) == false) 
	{
	datefield.select();
	alert("That date is invalid.  Please try again.");
	datefield.focus();
	return false;
	}
else 
	{
	return true;
   	}
}





function chkdate(objName) 
{
	var strDatestyle = "US";
	var strDate;
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	
	var intday;
	var intMonth;
	var intYear;
	var errorFound = false;

	var datefield = objName;
	var strSeparatorArray = new Array("-"," ","/",".");
	var intElementnum;
	var error = 0;

	var minYear=2006;
	var maxYear=2010;
	var strMonthArray = new Array(12);
		strMonthArray[0] = "Jan";
		strMonthArray[1] = "Feb";
		strMonthArray[2] = "Mar";
		strMonthArray[3] = "Apr";
		strMonthArray[4] = "May";
		strMonthArray[5] = "Jun";
		strMonthArray[6] = "Jul";
		strMonthArray[7] = "Aug";
		strMonthArray[8] = "Sep";
		strMonthArray[9] = "Oct";
		strMonthArray[10] = "Nov";
		strMonthArray[11] = "Dec";
	
strDate = datefield.value;




if (strDate.length < 1) 
	{
	return true;
	}


for (intElementnum = 0; intElementnum < strSeparatorArray.length; intElementnum++)
 {
	if (strDate.indexOf(strSeparatorArray[intElementnum]) != -1) 
	{
	strDateArray = strDate.split(strSeparatorArray[intElementnum]);
		if (strDateArray.length != 3) 
		{
		err = 1;
		return false;
		}
		else 
		{
		strDay = strDateArray[0];
		strMonth = strDateArray[1];
		strYear = strDateArray[2];
		}
errorFound = true;
	}
}



if (errorFound == false) 
{
	if (strDate.length>5) 
	{
	strDay = strDate.substr(0, 2);
	strMonth = strDate.substr(2, 2);
	strYear = strDate.substr(4);
   	}
}




if (strYear.length == 2) 
	{
	strYear = '20' + strYear;
	}


//Style of Date:

if (strDatestyle == "US") 
	{
	strTemp = strDay;
	strDay = strMonth;
	strMonth = strTemp;
	}


intday = parseInt(strDay, 10);
	if (isNaN(intday)) 
	{
	error = 2;
	return false;
	}



intMonth = parseInt(strMonth, 10);

if (isNaN(intMonth)) 
{
	for (i = 0;i<12;i++) 
	{
		if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) 
		{
		intMonth = i+1;
		strMonth = strMonthArray[i];
		i = 12;
   		}
	}

	if (isNaN(intMonth))
 	{
	error = 3;
	return false;
  	 }
}




intYear = parseInt(strYear, 10);
if (isNaN(intYear)) 
{
	error = 4;
	return false;
}



if (strYear.length != 4 || intYear==0 || intYear<minYear || intYear>maxYear)
{
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
}


if (intMonth>12 || intMonth<1)
 {
error = 5;
return false;
}

if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1))
{
error = 6;
return false;
}


if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
error = 7;
return false;
}


if (intMonth == 2) 
{
	if (intday < 1) 
	{
	error = 8;
	return false;
	}
if (LeapYear(intYear) == true) 
	{
	if (intday > 29)
	 {
	  error = 9;
	  return false;
	  }
	}
 else 
  {
	if (intday > 28) 
	{
	 error = 10;
	 return false;
 	}
   }
}




if (strDatestyle == "US") 
{
	datefield.value = strMonthArray[intMonth-1] + " " + intday+" " + strYear;
}

else 
{
datefield.value = intday + " " + strMonthArray[intMonth-1] + " " + strYear;
}
return true;
}





function LeapYear(intYear) 
   {
	if (intYear % 100 == 0) 
	{
	if (intYear % 400 == 0) { return true; }
	}
	else 
   	{
	if ((intYear % 4) == 0) { return true; }
   	}
	return false;
   }




function doDateCheck(fromDate, toDate) 
{
	if (Date.parse(fromDate.value) <= Date.parse(toDate.value)) 
	{
	alert("The dates are valid.");
	}
	else 
	{
		if (fromDate.value == "" || toDate.value == "") 
		alert("Both dates must be entered.");
	else 
	alert("To date must occur after the from date.");
   	}
}

HTML:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

  

<meta http-equiv="Content-Script-Type" content="text/javascript"/>
<script type="text/javascript" src = "code.js"></script>


<!--Sytle Sheet-->

<link href="mystyle.css" rel="stylesheet" type="text/css" />



<title>Welcome To Hardly Normal-Employee Information Form</title>
 
</head>


<body>

<p>
<img class="pos" src="banner1.jpg" alt="banner"/>
</p>
  <p>
    <a href="http://validator.w3.org/check?uri=referer"><img
        src="http://www.w3.org/Icons/valid-xhtml10"
        alt="Valid XHTML 1.0 Strict" height="31" width="88" /></a>
  </p>
<h1>
Welcome To Hardly Normal-Employee Information Form
</h1>


 			<!--First Para-->
		
 <div class="box">
 	<p>
 	 The performance planning and review process is intended to assist
 	 supervisors to review the performance of staff during a given period (at least annually)
 	 and develop agreeed performance plans based on workload agreements
	 and the strategic direction of Hardly Normal<sup>TM</sup>.
	 <br/>
	 The Performance Planning and Review system covers both results (what was accomplished),
	 and behaviours (how those results were achieved). The most important aspect
	 is what will be accomplished in the future and how this will be
 	 achieved within a defined period. The process is continually woking towards
 	 creating improved performance and behaviours that align and contribute
 	 to the mission and values of Hardly Normal <sup>TM</sup>.
	 </p>
</div>

 						<!--Form-->


 <form id="EmployeeInfo" method="post" action="http://tl28serv.uws.edu.au/twainfo/form.asp" onsubmit="return validate_form(this)" >
 

<fieldset>

<legend>

		Employee Information Form:

</legend>


				<!--Personal Information-->

		<p>Given Name:*
	
		<input type="text" name="Givname" size="45" maxlength="35" id="Givname" onchange="return ValidateText(this)" />
	</p>
		<p>Family Name:*

	
		<input type="text" name="FamName" size="45" maxlength="35" id="FamName" onchange="return ValidateText(this)" />
	
</p>
			
		<p>Phone Extension*:

		<input type="text" name="Ext" size="6" maxlength="4" id="Ext" onchange="return validateNum(this)"/>
	</p>
		<p>Email:*
		<input type="text" name="Mail" id="Mail"/>
</p>

	



			 <!--Employee Information-->

 			<h3>Employment Information:</h3>
			
	 <p class="man">
	 (The feilds marked with * are mandatory)
	 </p>


	 <p>Employee ID:*
 	 <input type="text" name="EmpID" size="10" maxlength="8" id="EmpID" onchange="return validateNum(this)"/>

 	</p>
	<p>Job Title:*

 	<select name="jobTitle" size="1" id="jobTitles">

 	<option value="PC">----Please Choose----</option>
 	<option value="SP">Sales Person </option>
 	<option value="SM">Sales Manager </option>
 	<option value="DM">Department Manager </option>
 	<option value="WP">Warehouse Person </option>
 	<option value="WM">Warehouse Manager </option>
 	</select>
</p>
	
 	<p>Employee Mode:
 	<select name="class1" size="1">
	<option value="PC">----Please Choose----</option>
 	<option value="PT"> Part Time </option>
 	<option value="Cas"> Casual </option>
	<option value="FT"> Full Time </option>
	</select></p>
 	

	<p>Department
	<select name="Dept" size="4" multiple="multiple">
	<option value="Elec"> Electrical</option>
 	<option value="Comp"> Computer </option>
 	<option value="Fur"> Furniture </option>
 	<option value="Bed"> Bedding </option>
 	</select>
</p>

	<p>Supervisor Name:*
 	<input type="text" name="Sup" size="40" maxlength="80" id="Sup" onchange="return ValidateText(this);"/>
   </p>


		
	 <p>Review Period:*</p>
	

	<p>From:* 
	 <input type="text" id="fromDate" name="fromDate" maxlength= "11"/>
</p>
 	<p>
	 End Date:*
	 
 	<input type="text" id="toDate" name="toDate" maxlength="11"/>
	</p>
<p>
		
		<input type="submit" value="Submit" />
		<input type="reset" value="Reset" />
	</p>	


</fieldset>
</form>
<p class="side">
To visit the Ratings Form please click on the following Link:
</p>
<ul id="nav">

	<li><a href="Ratings.html"> [Ratings Page] </a></li>
</ul>


</body>
</html>

I dont know why,but the validation is working fine in Firefox,but in IE it doesnt work!!Could u please let me know whats wrong with it?

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Roses89
0

I don't know what else may be wrong, but "super" is a reserved word in IE; using it as a variable name causes an error.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.