We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

How do I iterate nameless elements

CycnoAB
CycnoAB asked
on
Medium Priority
163 Views
Last Modified: 2008-03-17
Hello.
I'm programming an application that displays a list of selected database tulips with some restriction in information due to simplicity in the list. However I got a request to enable an option to "expand" every row, displaying the "short description" of the tulip. Easy enough. Now, when a user select a table row it displays the complete information in another frame and sets the row to selected. This works fine with one row, but with the expanding row I've encountered problems. With my current scipt I only select the first row.
Here's an example:

<tr onmouseover="className='highlight_row';" class="e_r" onmouseout="m_ou(this,'e_r');"onclick="cli(this,'e_r',99,'all');">
      <td width="15" style="padding-left: 2px;">&nbsp;</td>
      <td nowrap>Company name</td>
      <td nowrap>Contract description</td>
      <td align="right"><img title="Copy to clipboard" onclick="cli_copy(99);" height="12" src="../images/copy.gif" width="12">&nbsp;</td>
</tr>
<tr class='e_r'>
      <td>&nbsp;</td>
      <td colspan='3'>Expanded description using 3 columns.</td>
</tr>

Without the expanded row the last TR is not executed.
I realize I might be able to work around this by putting it all into a table in each row in the main table, but my curiousity drives me to see if there is a way to solve this. The javascript function works as follow atm:
function cli(t,r,ci,op)
{
      -[data removed]-
      try{
            document.getElementById("h").className=old_rowtype;
            document.getElementById("h").id="";
      }catch(error){};
      t.id="h";
    old_rowtype=r;
    t.className="s_row";
}

So, how do I set both rows to selected (and deselect them when a new one is set)?

Thanks.
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2006
Commented:
Not fully sure if this is applicable for your situation, but you should be able to use something like this:

<style type="text/css">
tbody.closed tr.whenOpened {display:none;}
tbody.opened tr.whenClosed {display:none;}
</style>

<tbody class="closed">
   <tr>
     <td>This row is always visible</td>
     <td><a href="#" onclick="this.parentNode.parentNode.className='opened';" class="whenClosed">Expand</a></td>
   </tr>
   <tr class="whenOpened">
      <td colspan="2">Detailed description, only visible when tbody class equals 'opened'</td>
   </tr>
</tbody>
<tbody class="closed">
   <!-- another record -->
</tbody>

This way you don't have to mess with div ids and stuff. Also there can be multiple records be opened at the same time.

Hope this helps.

-r-

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
That was a very interesting piece of code I must admit.
What is the tbody entity you use? Does it work with table, the one I'm accustomed to? Because i tried and nothing happens (used IE and FF).

My problem pretty much comes down to changing class of the following TR class, so I guess I could change the name of the second one. I found a function called nextSibling which works out fine in IE, but not in FF. Is there a similat function to parentNode? Like nextNode or something like that?
CERTIFIED EXPERT
Top Expert 2006

Commented:
<tbody>,<thead>,<tfoot> are table tags using which you can group tr's.

You can have a single thead, multiple tbodys and single tfoot.

-r-

Author

Commented:
What's the pro:s of using them?
Are there any requirements to use them btw, since it's not working for me?
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.