Solved

javascript script error description: object required

Posted on 2011-02-17
8
496 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

751 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