Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Sep 2005
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need help with script

    Here's a script I have that basically allows me to have an infinate amount of hidden cells with the same id that can be expanded/contracted via an input in their header. My problem is that when you click "show" on one of them, then try to click "show" on another one, you have to click it two or three times to get it to work. Anyone know how to fix that? Here's the code:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    
    <html>
    <head>
    <title>Page title</title>
    <style type="text/css">
    <!--
    .showSwitch {
    	display: table-cell;
    }
    .hideSwitch {
    	display: none;
    }
    -->
    </style>
    <script type="text/javascript">
    
    var checkflag = "false";
    // Checks All Checkboxes
    function showall(form, theCommonNodeName) {
    theCommonNodeName = theCommonNodeName.toLowerCase();
    var theCommonNode = form.parentNode;
    while(theCommonNode.nodeName.toLowerCase() != theCommonNodeName && theCommonNode != document) {
    theCommonNode = theCommonNode.parentNode; }
    
    if (checkflag == "false") {
    var elements = theCommonNode.getElementsByTagName("td");
    for (var c = 0;  elements[c]; c++) 
    if (elements[c].id == 'dd1')
    {elements[c].className="showSwitch";}
    checkflag = "true";
    return "Hide"; 
    }
    else if (checkflag == "true"){
    var elements = theCommonNode.getElementsByTagName("td");
    for (var c = 0;  elements[c]; c++) 
    if (elements[c].id == 'dd1')
    {elements[c].className="hideSwitch";}
    checkflag = "false";
    return "Show"; }
    }
    
    </script>
    </head>
    <body>
    <table>
    	<tr>
    		<td>
    			<table>
    				<tr>
    					<td>
    					<input type=button value="Show" onClick="this.value=showall(this, 'table');">
    					</td>
    				</tr>
    				<tr>
    					<td class="hideSwitch" id="dd1">
    						<table>
    							<tr>
    								<td>1</td><td>2</td><td>3</td>
    							</tr>
    						</table>
    					</td>
    				</tr>
    			</table>
    		</td>
    	</tr>
    		<tr>
    		<td>
    			<table>
    				<tr>
    					<td>
    					<input type=button value="Show" onClick="this.value=showall(this, 'table');">
    					</td>
    				</tr>
    				<tr>
    					<td class="hideSwitch" id="dd1">
    						<table>
    							<tr>
    								<td>1</td><td>2</td><td>3</td>
    							</tr>
    						</table>
    					</td>
    				</tr>
    			</table>
    		</td>
    	</tr>
    		<tr>
    		<td>
    			<table>
    				<tr>
    					<td>
    					<input type=button value="Show" onClick="this.value=showall(this, 'table');">
    					</td>
    				</tr>
    				<tr>
    					<td class="hideSwitch" id="dd1">
    						<table>
    							<tr>
    								<td>1</td><td>2</td><td>3</td>
    							</tr>
    						</table>
    					</td>
    				</tr>
    			</table>
    		</td>
    	</tr>
    </table>
    
    
    </body>
    </html>

  • #2
    Regular Coder
    Join Date
    Aug 2005
    Location
    Toronto, ON, Canada
    Posts
    231
    Thanks
    0
    Thanked 0 Times in 0 Posts
    your code works only for dd1

    Code:
            if (elements[c].id == 'dd1') {
                elements[c].className="showSwitch";
            }
    is it a school project
    rm -f /

  • #3
    New Coder
    Join Date
    Sep 2005
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    the code works fine, other than the item i describe above.

  • #4
    Regular Coder
    Join Date
    Aug 2005
    Location
    Toronto, ON, Canada
    Posts
    231
    Thanks
    0
    Thanked 0 Times in 0 Posts
    In FF only dd1 works, what browser do you use?
    rm -f /


  •  

    Posting Permissions

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