SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist perpetual_dream's Avatar
    Join Date
    Nov 2005
    Location
    Jerusalem
    Posts
    542
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Hide/Show elements with a specific ID

    Hello,

    I am trying to show/hide all the elements with a specific id.... The following works fine for id='1' but doesn't work out for id='2'. I don't know why! wish anyone can help

    Code HTML4Strict:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head><title>
    	Untitled Page
    </title>
          function ToggleMenuOnOff (menuName) {
      var i=0;
      var elementCount=0;
     
    elementCount = document.all(menuName).length;
    for (i=0; i<elementCount; i++) {
    if (document.all(menuName,i).style.display == 'none') {
     
    document.all(menuName,i).style.display = 'block';
        } else {
          document.all(menuName,i).style.display = 'none';
        }
     
    }
    }
     
        </script>
    <link href="App_Themes/TaskWebsiteTheme/Style.css" type="text/css" rel="stylesheet" />
    </head>
    <body>
        <form name="form1" method="post" action="test.aspx" id="form1">
     
     
        <div>
            <TABLE id="Table1" border="0">
     
     
     
            <TR><TD><b><u><a  style="cursor:hand;" onmousedown="ToggleMenuOnOff('1')">msn 9.0</a></u></b></TD>
     
            </TR>
             <tr style="display:none" id="1"><td colspan="2" ><a href="Aljazeera.net
    ">Download</a></center></td>
    </tr>
     
     
    <TR style="display:none" id="1" >
    	<TD> 9999	
      </TD>
     
       <td>fixed the batee5</td>
         </TR>	
     
      <TR style="display:none" id="1" >	<TD> 2	
      </TD>
     
      <td>nobigchangereally</td>
       </TR>	</div>   
     
            <TR><TD><b><u><a  style="cursor:hand;" onmousedown="ToggleMenuOnOff('2')">yahoo</a></u></b></TD>
            </TR>
             <tr style="display:none" id="2"><td colspan="2" ><a href="yahoo.net
    ">Download</a></center></td></tr>
            </div>   </TABLE>
        </div>
        </form>
    </body>
    </html>
    Tanzeelnet - Best arabic downloadsite
    Linux Hosting |Free Downloads |

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There are several errors here. (I assume that the missing <script> start tag actually exists in the live page.)

    You have two elements with the same ID, which is not allowed. An ID must be unique. No two elements in a document can have the same ID.

    IDs must not start with a digit. They must start with a letter (A-Z or a-z).

    Always validate your markup before you start trouble-shooting anything else.
    Birnam wood is come to Dunsinane


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
  •