Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Simple Script - No Errors on Moz.(checked log) - IE Object Required Error

Reply
Thread Tools

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

 
 
imatts@gmail.com
Guest
Posts: n/a
 
      12-31-2006
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

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      12-31-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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.


--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
imatts@gmail.com
Guest
Posts: n/a
 
      12-31-2006
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/

Matt

 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      12-31-2006
(E-Mail Removed) wrote:
> 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.



--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
imatts@gmail.com
Guest
Posts: n/a
 
      12-31-2006
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

> 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.
>
>
>
> --
>
> Martin Honnen
> http://JavaScript.FAQTs.com/


 
Reply With Quote
 
Randy Webb
Guest
Posts: n/a
 
      12-31-2006
(E-Mail 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.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      12-31-2006
(E-Mail Removed) wrote:
> 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.

--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
imatts@gmail.com
Guest
Posts: n/a
 
      01-01-2007
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
innerHTML, IE5.0, Error 'Line: 0 Error: Object required Andrew Phillipo Javascript 1 09-27-2005 05:28 PM
Object creation - Do we really need to create a parent for a derieved object - can't the base object just point to an already created base object jon wayne C++ 9 09-22-2005 02:06 AM
Error: VBScript runtime (0x800A01A8) Object required: '[object]' Carolyn Speakman XML 1 07-30-2004 07:40 AM
Errors, errors, errors Mark Goldin ASP .Net 2 01-17-2004 08:05 PM
Script Object Required Error Glenn Javascript 0 09-13-2003 01:52 AM



Advertisments