Solved

javascript script error description: object required

Posted on 2011-02-17
8
490 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:shinuq
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
 

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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 17

Expert Comment

by:shinuq
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:
shinuq 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article discusses how to create an extensible mechanism for linked drop downs.
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now