Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

javascript script error description: object required

Posted on 2011-02-17
8
Medium Priority
?
514 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

705 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