Trouble finding hidden table

Discussion in 'Javascript' started by avanti, Dec 30, 2006.

  1. avanti

    avanti Guest

    Hi,

    I have some JavaScript code in an ASP page that shows or hides a table
    whenever a radio button is checked or unchecked. I use the
    table.style.dispay property to do this.

    However, in some cases the table is hidden on page_load. So, JS cannot
    find the table by ID and gives error whenever the radio button is
    clicked. Is there a way to solve this in JS?

    Thanks,
    Avanti
     
    avanti, Dec 30, 2006
    #1
    1. Advertising

  2. avanti

    Daz Guest

    avanti wrote:

    > Hi,
    >
    > I have some JavaScript code in an ASP page that shows or hides a table
    > whenever a radio button is checked or unchecked. I use the
    > table.style.dispay property to do this.
    >
    > However, in some cases the table is hidden on page_load. So, JS cannot
    > find the table by ID and gives error whenever the radio button is
    > clicked. Is there a way to solve this in JS?
    >
    > Thanks,
    > Avanti


    I'm not entirely sure why the problem seems to be intermitent. I would
    suggest you find out why the table is being hidden to start with.

    What is the error you are getting?

    Setting the display attribute to 'none' only hides the table from view,
    not from the DOM.

    Here's some code that might help. Note that the table starts out
    hidden, and a reference to the table is only obtained when the 'Toggle'
    span is clicked upon.

    <html>
    <head>
    <script type="text/javascript" language="javascript">
    function toggleTable()
    {
    var table = document.getElementById('table');
    table.style.display = (table.style.display) ? '' :
    'none';
    }
    </script>
    </head>
    <body>
    <span onclick="toggleTable()">Toggle</span>
    <table style='display: none;' id="table">
    <tr>
    <td>
    Top Left
    <td>
    Top Right
    <tr>
    <td>
    Bottom Left
    <td>
    Bottom Right
    </table>
    </body>
    </html>

    If you are still having problems, please post some of your code.

    Best regards.

    Daz.
     
    Daz, Dec 30, 2006
    #2
    1. Advertising

  3. avanti

    avanti Guest

    Thanks this helped with some other changes.

    Daz wrote:
    > avanti wrote:
    >
    > > Hi,
    > >
    > > I have some JavaScript code in an ASP page that shows or hides a table
    > > whenever a radio button is checked or unchecked. I use the
    > > table.style.dispay property to do this.
    > >
    > > However, in some cases the table is hidden on page_load. So, JS cannot
    > > find the table by ID and gives error whenever the radio button is
    > > clicked. Is there a way to solve this in JS?
    > >
    > > Thanks,
    > > Avanti

    >
    > I'm not entirely sure why the problem seems to be intermitent. I would
    > suggest you find out why the table is being hidden to start with.
    >
    > What is the error you are getting?
    >
    > Setting the display attribute to 'none' only hides the table from view,
    > not from the DOM.
    >
    > Here's some code that might help. Note that the table starts out
    > hidden, and a reference to the table is only obtained when the 'Toggle'
    > span is clicked upon.
    >
    > <html>
    > <head>
    > <script type="text/javascript" language="javascript">
    > function toggleTable()
    > {
    > var table = document.getElementById('table');
    > table.style.display = (table.style.display) ? '' :
    > 'none';
    > }
    > </script>
    > </head>
    > <body>
    > <span onclick="toggleTable()">Toggle</span>
    > <table style='display: none;' id="table">
    > <tr>
    > <td>
    > Top Left
    > <td>
    > Top Right
    > <tr>
    > <td>
    > Bottom Left
    > <td>
    > Bottom Right
    > </table>
    > </body>
    > </html>
    >
    > If you are still having problems, please post some of your code.
    >
    > Best regards.
    >
    > Daz.
     
    avanti, Jan 2, 2007
    #3
    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. Larry Bates

    Finding "hidden" syntax errors

    Larry Bates, Jun 11, 2004, in forum: Python
    Replies:
    1
    Views:
    381
    Miki Tebeka
    Jun 13, 2004
  2. Replies:
    1
    Views:
    420
  3. comphilip
    Replies:
    0
    Views:
    368
    comphilip
    Jan 10, 2009
  4. Rick
    Replies:
    3
    Views:
    8,580
    Alexey Smirnov
    Apr 13, 2010
  5. SolarCanine
    Replies:
    2
    Views:
    338
    SolarCanine
    Sep 20, 2005
Loading...

Share This Page