This function is causing errors for me in Internet Explorer - all other browsers show it correctly:
curDiv.style.display = "none";
Here's the full function....
%26lt;script type="text/javascript"%26gt;
var current = "1";
function pageSwitch(id){
if(!document.getElementById) return false;
var div = document.getElementById("page"+id);
var curDiv = document.getElementById("page"+current);
curDiv.style.display = "none";
div.style.display = "block";
current = id;
}
pageSwitch(1);
%26lt;/script%26gt;
I get 'Object Required' when I view the page in IE- works fine on Opera / Firefox etc....
Why is this line of Javascript giving me errors in Internet Explorer (but not other browsers)?microsoft outlook No need to reinstall Java... JavaScript is built into web browsers and have nothing to do with the Java Runtime.
However, for full browser compatibility, I recommend using the language tag also, ex:
%26lt;script type="text/javascript" language="javascript"%26gt;
On to the problem...
If you have your page posted somewhere, please provide a URL to view the page.
Without seeing the page, there are multiple causes. I'm going to assume the most common for beginners (and I apologize if you are not)...
In your code, your assigning "curDiv" the reference to an object with an elementID of "page1" when the page loads. So make sure you have an elementID of the same name (cAsE SenSITivE)!
Example:
%26lt;html%26gt;
%26lt;body%26gt;
%26lt;div id="page1"%26gt;I must exist when the page loads.%26lt;/div%26gt;
%26lt;/body%26gt;
%26lt;/html%26gt;
If it's not that, post up the URL and I can have a look at it to get a better view on what's happening. The function looks great, so I'm assuming the problem is somewhere with the function calls or the ID names...
Robert Roati
www.designwithattitude.com
After this posting, I tried this function myself with the following code, and all worked well:
%26lt;html%26gt;
%26lt;script type="text/javascript" language="javascript"%26gt;
var current = "1";
function pageSwitch(id){
if(!document.getElementById) return false;
var div = document.getElementById("page"+id);
var curDiv = document.getElementById("page"+current);
curDiv.style.display = "none";
div.style.display = "block";
current = id;
}
pageSwitch(1);
%26lt;/script%26gt;
%26lt;style type="text/css"%26gt;
#page1 {display: block;}
#page2 {display: none; }
#page3 {display: none; }
%26lt;/style%26gt;
%26lt;body%26gt;
%26lt;img id="page1" onclick="pageSwitch(2)" src="1.bmp" /%26gt;
%26lt;img id="page2" onclick="pageSwitch(3)" src="2.bmp" /%26gt;
%26lt;img id="page3" onclick="pageSwitch(1)" src="3.bmp" /%26gt;
%26lt;/body%26gt;
%26lt;/html%26gt;
... nice function by the way.
Why is this line of Javascript giving me errors in Internet Explorer (but not other browsers)?windows messenger internet explorerThanks, it wouldn't let me pick a best answer when I tried a few weeks back :) Report It
You could try this to see if it will solve the problem,
uninstall the java application from the Add/Remove programs then visit their website and download a fresh copy of java and install the application again the web address is,
http://www.java.com
good luck.
I'll tell you why IE pumps up an error for it- IE sucks. Plain and simple. It manages to find errors in everything...somehow.