Link to home
Start Free TrialLog in
Avatar of jescot
jescotFlag for Australia

asked on

javascript script error description: object required

This error comes up on Internet explorer but not firefox.
------------------------------------------------------------
javascript script error description: object required -
Source www.example.com.au/tst.php - line 119
This then breaks the calc script
Any ideas???
<script type="text/javascript">
<!--
// Change background colors when focus set
	window.onload = init;
	function init() {
  		for(var i=0;i<document.RegistrationForm.length;i++) {
    	document.RegistrationForm[i].onfocus = document.RegistrationForm[i].onblur = changeBg;
  }
}

	function changeBg(evt) {
 		var szEvent = "object" == typeof(event) ? event.type : evt.type;
 		this.style.background = szEvent == "focus" ? "#C9EDFC" : "transparent";
										// color light brown- #DACFB8, rose-#ffc0cb
}
// Calculate Totals
	function calcTotal(){
	
		fieldsArray = ['price1',];
		
		Total = 0;
		
		for(i=0; i<fieldsArray.length; i++){
		
			Total += parseInt(document.getElementById(fieldsArray[i]).value);
			
		 alert("Don't forget -each paid attendee can bring another person for FREE.");
		
		}
		
		document.getElementById("Total").value = Total;
	    document.RegistrationForm.Amount.value = document.RegistrationForm.Total.value;
	}

Open in new window

Avatar of chaitu chaitu
chaitu chaitu
Flag of India image

have u defined id="Total" in ur file.better to send full code.
Avatar of leakim971
work fine for me :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_26827824.html</title>
<script type="text/javascript">

window.onload = calcTotal;

	function calcTotal(){
	
		fieldsArray = ['price1',];
		
		Total = 0;
		
		for(i=0; i<fieldsArray.length; i++){
		
			Total += parseInt(document.getElementById(fieldsArray[i]).value);
			
		 alert("Don't forget -each paid attendee can bring another person for FREE.");
		
		}
		
		document.getElementById("Total").value = Total;
	    document.RegistrationForm.Amount.value = document.RegistrationForm.Total.value;
	}

</script>
</head>
<body>
<form name="RegistrationForm">
price 1 :<input id="price1" value="100" type="text"/><br />
total :<input name="Total" id="Total" value="0" type="text"/>
amount :<input name="Amount" value="0" type="text"/>
</form>
</body>
</html>

Open in new window


so you have a problem in your html, check the case in each attributes of your fields (id, name)
Update your function with this condition

Hope this helps
if(typeof(document.getElementById(fieldsArray[i])) == 'object')
 Total += parseInt(document.getElementById(fieldsArray[i]).value);

Open in new window

Avatar of jescot

ASKER

Tried all 3 solutions and yes it works fine in Firefox but in internet explorer it keeps giving me an error.
javascript script error description: object required Line 119 or Line 120
What version of IE is causing the error?
Avatar of jescot

ASKER

Internet Explorer 7.0
to be exact 7.0.5730.11
ASKER CERTIFIED SOLUTION
Avatar of Shinesh Premrajan
Shinesh Premrajan
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jescot

ASKER

Thanks