Advertisement

11.11.2005 at 02:37PM PST, ID: 21628290
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.4

Expand / Collapse table rows

Asked by ayumi in JavaScript

Tags: , , ,

Hi All,
I have this code with me (I got it from some website, do not remember now) which expand / collapse table rows. I want to add + / - image before it and switch it depending on if it is expanded or collapsed. Can someone help me extending this script. It is very simple, you can copy/paste following code in notpade and save as html file.

If someone has better solution then that will also work.

------------------------------------------------
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">

<title>Expand / Collapse</title>

<script>
      var toggledDisplay = new Object();
    toggledDisplay['sub1'] = true;
    toggledDisplay['sub2'] = true;
    toggledDisplay['sub3'] = true;

function toggleDisplay(bDisplayed)
{
  if(!document.getElementById || toggleDisplay.arguments.length < 2) return;
  var displayed = new Object();
      displayed['true'] = 'block';
      displayed['false'] = 'none';
  for(var i = 1; i < toggleDisplay.arguments.length; i++)
  {
    oDisplay = document.getElementById(toggleDisplay.arguments[i]);
    if(oDisplay)
    {
      oDisplay.style.display = displayed[bDisplayed];
      // mozilla is the only browser out of the lot that can't get this right.  so, if we're
      // setting an object's display style to block, we gotta reload any images contained
      // within that block.  mozilla won't do it for you like every other browser that
      // supports the functionality of changing the display style dynamically.
      // begin crap browser hack
      if(bDisplayed)
      {
        oImages = oDisplay.getElementsByTagName('IMG');
        for(var j = 0; j < oImages.length; j++)
          oImages[j].src = oImages[j].src;
      }
      // end mozilla, err, crap browser hack
       if(typeof toggledDisplay[toggleDisplay.arguments[i]] != 'undefined')
        toggledDisplay[toggleDisplay.arguments[i]] = !bDisplayed;
    }
  }
}

</script>

</HEAD>
<BODY>

  <a href="JavaScript://" onclick="toggleDisplay(true, 'sub1', 'sub2', 'sub3' , 'sub4', 'sub5', 'sub6', 'sub7');">Expand All</a> | <a href="JavaScript://" onclick="toggleDisplay(false, 'sub1', 'sub2', 'sub3' , 'sub4', 'sub5', 'sub6', 'sub7');">Collapse All</a>
<font color="#000000">
<table border="1">
    <tr>
        <th>Fname</th>
        <th>LName</th>
        <th>Title</th>
    </tr>
    <tr>
        <td colspan="3"><a href="JavaScript://" onclick="toggleDisplay(toggledDisplay['sub1'], 'sub1')">Corporate Staff</a><td>
    </tr>
    <tr id="sub1">
            <td colspan="3">
            <table>
            <tr>
                <td>User 1</td>
                <td>User 1</td>
                <td>User 1</td>
            </tr>
            <tr>
                <td>User 2</td>
                <td>User 2</td>
                <td>User 2</td>
            </tr>
            <tr>
                <td>User 3</td>
                <td>User 3</td>
                <td>User 3</td>
            </tr>
            </table>
            </td>
    </tr>    
    <tr>
        <td colspan="3"><a href="JavaScript://" onclick="toggleDisplay(toggledDisplay['sub2'], 'sub2')">Group one</a></td>
    </tr>
    <tr id="sub2">
            <td colspan="3">
            <table>
            <tr>
                <td>User 1</td>
                <td>User 1</td>
                <td>User 1</td>
            </tr>
            <tr>
                <td>User 2</td>
                <td>User 2</td>
                <td>User 2</td>
            </tr>
            </td>            
            </table>
    </tr>    
    <tr>
        <td colspan="3"><a href="JavaScript://" onclick="toggleDisplay(toggledDisplay['sub3'], 'sub3')">Group Two</a></td>
    </tr>
    <tr id="sub3">
            <td colspan="3">
            <table>
            <tr>
                <td>User 1</td>
                <td>User 1</td>
                <td>User 1</td>
            </tr>            
            </table>
            </td>
    </tr>    
</table>
</font>
      
  <script language="JavaScript" type="text/javascript">
  <!--
    toggleDisplay(false, 'sub1', 'sub2', 'sub3', 'sub4', 'sub5', 'sub6', 'sub7');
    toggleDisplay(true, 'toggleAll');
  //-->
  </script>

</BODY>
</HTML>
Start Free Trial
 
 
[+][-]11.11.2005 at 02:46PM PST, ID: 15277446

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.11.2005 at 03:55PM PST, ID: 15277779

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.11.2005 at 04:06PM PST, ID: 15277853

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: JavaScript
Tags: collapse, table, javascript, expand
Sign Up Now!
Solution Provided By: amit_g
Participating Experts: 2
Solution Grade: A
 
 
[+][-]11.14.2005 at 10:21AM PST, ID: 15289687

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.14.2005 at 11:40AM PST, ID: 15290342

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.14.2005 at 01:37PM PST, ID: 15291259

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-44