Simple Script - No Errors on Moz.(checked log) - IE Object Required Error

I

imatts

Hi can anyone help with this little problem. I have a simple script to
swap between two divs on a page. It works perfectly in Firefox & Safari
& Opera. It fails in IE 6 giving Object Required error on initializing
second variable var layer2. I can't get to the bottom of this. Can
anyone help?

<script type="text/javascript">
function showhide(element) {
var layer1 = document.getElementById('layer1').style;
var layer2 = document.getElementById('layer2').style;
if (element == "php"){
layer1.visibility= "hidden";
layer2.visibility= "visible";
}
else if (element == "java") {
layer2.visibility= "hidden";
layer1.visibility= "visible";
}
}
</script>

<div id="layer1" style="visibility:visible">
<a href="javascript:showhide('php');">Click here for some PHP
examples</a>
.....</div>
<div id="layer2" style="visibility:hidden">
<a href="javascript:showhide('java');">Click here to see Java
examples</a>
.....</div>

Thanks. Matt
 
M

Martin Honnen

Hi can anyone help with this little problem. I have a simple script to
swap between two divs on a page. It works perfectly in Firefox & Safari
& Opera. It fails in IE 6 giving Object Required error on initializing
second variable var layer2. I can't get to the bottom of this. Can
anyone help?

var layer2 = document.getElementById('layer2').style;
<div id="layer2" style="visibility:hidden">


With that information I don't see why you would get an error. Consider
posting a URL to a minimal but complete example that shows us the error.
 
M

Martin Honnen

Hi Martin. I wasn't keen on posting my site as it's not finished yet,
but here goes anyway. The example is quite simple. Just click on the
'Click here for...' link near the top of the page.

http://roadsidepicnic.co.uk/code/

Somehow IE has problems with your markup and loses the div id="layer2".
I suspect that your XHTML that is partly not marked up to be backwards
compatible with HTML is the problem. So use e.g.
<br />
and not
<br/>
use
<img />
and not
<img/>
and make that
<applet code="TicTacToe.class" archive="TicTacToe.jar" width="570"
height="600"></applet>
with a closing </applet> tag, don't use pure XML
<applet code="TicTacToe.class" archive="TicTacToe.jar" width="570"
height="600"/>
as HTML parsers might have problems with that.

I however have not tried whether that fixes the problem, I hope it does.
 
I

imatts

It worked! The </applet> tag was all that was needed. I didn't realise
IE 6 had problems with XHTML - quite an important thing to know,
though. Thanks very much Martin, you made my day. Now I can finish my
site...

Happy New Year!

Matt
 
R

Randy Webb

(e-mail address removed) said the following on 12/31/2006 11:52 AM:
It worked! The </applet> tag was all that was needed. I didn't realise
IE 6 had problems with XHTML - quite an important thing to know,
though.

No version of IE, not even IE7, knows what XHTML is. It parses it as
tag-soup HTML and what you get as a result to try to script is a guess
at best.
 
M

Martin Honnen

The </applet> tag was all that was needed. I didn't realise
IE 6 had problems with XHTML - quite an important thing to know,
though.

If you choose to use XHTML and serve it as text/html then you should
follow the guidelines in <http://www.w3.org/TR/xhtml1/#guidelines> to
ensure your XHTML markup is parsed as intended by HTML user agents like IE.
 
I

imatts

Thanks guys. That link is really helpfull. HTML vs XHTML was a bit of a
grey area for me I must admit. I thought if my pages passed validation
everything would be fine. Good to know though, so thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top