Results 1 to 5 of 5

Thread: Simple menu giving invalid ID

  1. #1
    Join Date
    Apr 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Simple menu giving invalid ID

    I'm trying to make a simple tree menu script to contract and expand certain tables & rows. However, it's telling me that it has an invalid ID specified. Here is what I'm doing:

    Code:
    <img src="collapse.gif" onclick="hideshow('pop',this);" style="cursor: hand; display: ''; float: right;" />
    Code:
    <tbody id="pop" style="display: block;">...table rows etc etc...</tbody>
    Code:
    function hideshow(id, imgthis) {
     if(document.getElementById(id).style.display == "block" || document.getElementById(id).style.display == "") {
      document.getElementById(id).style.display = "hidden";
    imgthis.src="collapse_collapsed.gif";
     } else if(document.getElementById(id).style.display == "hidden") {
      document.getElementById(id).style.display = "";
    imgthis.src="collapse.gif";
     }
    }
    What am I doing wrong?

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by realwx View Post
    What am I doing wrong?
    Code:
    <tbody id="pop"
    Apply the id to the entire table.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Apr 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by jscheuer1 View Post
    Code:
    <tbody id="pop"
    Apply the id to the entire table.
    I don't think that is going to work... I have it as:

    Code:
    <table ...>
    <tr><td>Category 1 ...insert dropdown code here...</td></tr>
    <tbody id="pop">
    <tr><td>one</td></tr>
    <tr><td>two</td></tr>
    <tr><td>three</td></tr>
    </tbody>
    </table>

  4. #4
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    No, set the id to the table:
    Code:
    <table id="pop" ...
    - Mike

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I think what you (not you mburt) are missing here is that you cannot reinvent the structure of an HTML table simply to suit your purposes. Where you have:

    Code:
    <table ...>
    <tr><td>Category 1 ...insert dropdown code here...</td></tr>
    <tbody id="pop">
    <tr><td>one</t . . .
    This:

    Code:
    <tr><td>Category 1 ...insert dropdown code here...</td></tr>
    is included in the tbody even though you have placed it in the wrong spot.

    You would be better off redesigning without the table or, if you must use a table, have the entire table be acted upon by code that is outside of the table. Or act upon individual td's (preferably td's that occupy an entire row).
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •