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

Discussion in 'Javascript' started by imatts@gmail.com, Dec 31, 2006.

  1. Guest

    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
    , Dec 31, 2006
    #1
    1. Advertising

  2. Re: Simple Script - No Errors on Moz.(checked log) - IE Object RequiredError

    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/
    Martin Honnen, Dec 31, 2006
    #2
    1. Advertising

  3. Guest

    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
    , Dec 31, 2006
    #3
  4. Re: Simple Script - No Errors on Moz.(checked log) - IE Object RequiredError

    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/
    Martin Honnen, Dec 31, 2006
    #4
  5. Guest

    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/
    , Dec 31, 2006
    #5
  6. Randy Webb Guest

    Re: Simple Script - No Errors on Moz.(checked log) - IE Object RequiredError

    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/
    Randy Webb, Dec 31, 2006
    #6
  7. Re: Simple Script - No Errors on Moz.(checked log) - IE Object RequiredError

    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/
    Martin Honnen, Dec 31, 2006
    #7
  8. Guest

    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.
    , Jan 1, 2007
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Goldin

    Errors, errors, errors

    Mark Goldin, Jan 17, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    938
    Mark Goldin
    Jan 17, 2004
  2. yurps
    Replies:
    1
    Views:
    6,882
    rajeshthangarasu1983
    Feb 29, 2008
  3. Emiliano
    Replies:
    2
    Views:
    319
    Rajesh.V
    Oct 16, 2003
  4. Jason

    log asp script errors to a file

    Jason, Jun 6, 2006, in forum: ASP General
    Replies:
    3
    Views:
    180
    Jason
    Jun 7, 2006
  5. Bas Cost Budde

    IE: Object expected; Moz: runs fine

    Bas Cost Budde, Feb 5, 2004, in forum: Javascript
    Replies:
    3
    Views:
    97
    kaeli
    Feb 6, 2004
Loading...

Share This Page