Solved

javascript script error description: object required

Posted on 2011-02-17
8
495 Views
Last Modified: 2012-08-13
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

0
Comment
Question by:jescot
8 Comments
 
LVL 20

Expert Comment

by:chaitu chaitu
ID: 34915451
have u defined id="Total" in ur file.better to send full code.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 34915473
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)
0
 
LVL 17

Expert Comment

by:Shinesh Premrajan
ID: 34915476
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

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jescot
ID: 34943123
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
0
 
LVL 17

Expert Comment

by:Shinesh Premrajan
ID: 34948623
What version of IE is causing the error?
0
 

Author Comment

by:jescot
ID: 34950208
Internet Explorer 7.0
to be exact 7.0.5730.11
0
 
LVL 17

Accepted Solution

by:
Shinesh Premrajan earned 500 total points
ID: 34950713
<script type="text/javascript">
function mover(obj) {
      if (typeof(obj) != "object") { document.location.href = obj.replace("redirp.htm","redirps.htm"); }
      else { obj.href = obj.href.replace("redirp.htm","redirps.htm"); }
}
</script>

I find a code in the HTML page, i think that you forgot to mention here. Here the condition is failing

if (typeof(obj) != "object") { document.location.href = obj.replace("redirp.htm","redirps.htm"); }

And in that condition u have defined obj.replace, which is incorrect,

Hope this helps



0
 

Author Closing Comment

by:jescot
ID: 36471541
Thanks
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Only allow one check box 17 37
ASP get fieds value 2 20
Problem evaluating javascript equality expression 8 17
javascript and jquery question 4 20
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question