Workaround for document.getElementById("mydiv").style.display='none'

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • gimme_this_gimme_that@yahoo.com

    Workaround for document.getElementById("mydiv").style.display='none'

    Hi,

    I have an onchange method for a select box that goes something like
    this (the select is in a form named aForm):

    function page_on_change( ) {
    pageElement = aForm.my_page_i d;
    aForm.nav_page_ name.value =
    pages[pageElement.opt ions[ pageElement.sel ectedIndex ].value];
    var si = pageElement.sel ectedIndex;
    for ( i = 0 ; i < pages.size ; i++ ) {
    document.getEle mentById("id_" + i).style.displa y='none';
    }
    document.getEle mentbyId("id_" + si).style.displ ay='none';
    }

    IE fails on the statement:

    document.getEle mentbyId("id_" + si).style.displ ay='none';

    and says it doesn't support this property.

    What is the workaround?

    Thanks.

  • Walton

    #2
    Re: Workaround for document.getEle mentById(&quot; mydiv&quot;).st yle.display='no ne'

    IE fails on the statement:
    >
    document.getEle mentbyId("id_" + si).style.displ ay='none';
    Capitalize 'By' in getElementById. Javascript is case-sensitive.

    Comment

    • gimme_this_gimme_that@yahoo.com

      #3
      Re: Workaround for document.getEle mentById(&quot; mydiv&quot;).st yle.display='no ne'

      Thanks Walton,

      Great catch.

      Now a message popus up that says Object required.

      I've eyeballed the source and confirmed that divs id_0,id_1 etc exist.


      On Mar 16, 12:29 pm, "Walton" <jrhol...@gmail .comwrote:
      IE fails on the statement:
      >
      document.getEle mentbyId("id_" + si).style.displ ay='none';
      >
      Capitalize 'By' in getElementById. Javascript is case-sensitive.

      Comment

      • gimme_this_gimme_that@yahoo.com

        #4
        Re: Workaround for document.getEle mentById(&quot; mydiv&quot;).st yle.display='no ne'

        Opps. I got it. Thanks.

        Comment

        • =?ISO-8859-1?Q?G=E9rard_Talbot?=

          #5
          Re: Workaround for document.getEle mentById(&quot; mydiv&quot;).st yle.display='no ne'

          gimme_this_gimm e_that@yahoo.co m wrote :
          Thanks Walton,
          >
          Great catch.
          >
          Now a message popus up that says Object required.



          You are not correctly accessing form elements.
          I have an onchange method for a select box that goes something like
          this (the select is in a form named aForm):
          >
          function page_on_change( ) {
          pageElement = aForm.my_page_i d;
          aForm.nav_page_ name.value =
          pages[pageElement.opt ions[ pageElement.sel ectedIndex ].value];
          You must access the form element like this:

          document.forms["aForm"]
          and not like
          aForm

          Accessing Elements with the W3C DOM
          The MDN Web Docs site provides information about Open Web technologies including HTML, CSS, and APIs for both Web sites and progressive web apps.


          Referencing Forms and Form Controls by comp.lang.javas cript newsgroup
          FAQ notes


          Referencing Forms and Form elements correctly, Javascript Best
          Practices, by Matt Kruse


          Gérard
          --
          Using Web Standards in your Web Pages (Updated Dec. 2006)
          The MDN Web Docs site provides information about Open Web technologies including HTML, CSS, and APIs for both Web sites and progressive web apps.

          Comment

          Working...