Solved

How can I show/hide rows in a HTML table, but 1st row always show

Posted on 2009-05-05
8
282 Views
Last Modified: 2012-06-27
Hi all,

I am generated some HTML / Javascript through the use of some XSLT, and what I aim to do is generate a table with many rows where we always have the 1st row showing (which has a +/- image there for users to click so that they can expand/collapse the rest of the rows in that table). I am having trouble with the Javascript on assigning the relevant class to the rows so that they get hidden or shown.

So far my XSL is generating the HTML table that is shown.

I know I am violating HTML here by having many tags with the same ID, but I am just looking for ways to get this to work.

Is anyone able to help me out a bit here and also suggest what I place in my 'ShowHide()' javascript method?

Thanks in advance
<table class="InfoBlock" cellspacing="0" cellpadding="0">
      <col class="report_column_headings">
      <col class="report_column_headings">
      <tbody>
        <th>Date</th>
        <th>Capital</th>
        <tr class="search_results_row_colour">
          <td class="collection_list"><a onClick="ShowHide('ID0EKFAC')"><img src="images/panel_Plus.gif" alt="expand/collapse section" class="expandable" onclick="changepic()" border="0"></a>07-03-2005</td>
          <td class="collection_list">3,000,000</td>
        </tr>
        <tr class="collapsed" id="ID0EOFAC">
          <td class="collection_list">27-07-2002</td>
          <td class="collection_list">15,000,000</td>
        </tr>
        <tr class="collapsed" id="ID0ESFAC">
          <td class="collection_list">23-10-2000</td>
          <td class="collection_list">100,000</td>
        </tr>
      </tbody>
    </table>

Open in new window

0
Comment
Question by:TrystHughes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 10

Accepted Solution

by:
bugada earned 50 total points
ID: 24303901
If your show/hide is supposed to hide/show a single row you can use some sort of javascript like the following:
function ShowHide(id) {
   var elem = document.getElementById(id);
   if (elem) {
      elem.style.display = elem.style.display == "none" ? "block" : "none";
   }
   return false;
}

Open in new window

0
 
LVL 41

Assisted Solution

by:HonorGod
HonorGod earned 50 total points
ID: 24303951
You could put the row to not be displayed in the <thead> section, then the code can hide all of the rows in the <tbody>
0
 

Expert Comment

by:metta0_3
ID: 24303970
Well CSS for hiding would be Create an inline style to have initially hidden control using below CSS

Style = "display:none"

There is also a javascript show method.

function ShowItem() {
    document.getElementById('controlID').show();
}

function hideItem() {
document.getElementById('controlID').style.visibility = 'hidden';
}
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 41

Expert Comment

by:HonorGod
ID: 24303977
Put the ShowHide() function in the <head> section of the document between beginning and ending script tags, like this:
<script type='text/javascript'>
  function ShowHide() {
    ...
  }
</script>

Open in new window

0
 
LVL 12

Assisted Solution

by:alien109
alien109 earned 25 total points
ID: 24303984
if you mark up your table as follows:

<table>
<thead>
    <tr>
        <td>this is the first row</td>
    </tr>
</thead>
<tbody id="bob">
    <tr>
        <td>this is all the other stuff that hides/shows</td>
    </tr>
</tbody>
</table>

You can target just the body (with the appropriate id...) of the table to hide/show and leave the head as visible.
0
 
LVL 12

Expert Comment

by:alien109
ID: 24303995
oops, HonorGod beat me to the punch.
0
 

Author Comment

by:TrystHughes
ID: 24306140
Hi all, and thanks for teh replies :)

It looks like i am going down the <thead><tbody> route, but I am having trouble with my XSL output side of this at the moment, but once I crack this I will come back onto Javascript side of it here.

...brb...
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 24309799
Thanks for the assist, and the points.

I'm sorry that you felt the answer(s) only warranted a B

Good luck & have a great day
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Where is this content coming from? 4 39
JSON help 8 46
emailing registered email addresses in phpmyadmin 5 65
My tooltip is not displaying correct 11 15
When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question