SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Aug 2004
    Location
    Atlanta
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Hide/Show TR Change Text

    I have a similar problem to the one listed here ./showthread.php?p=3475723
    But this gave me warning: Warning! You are replying to a thread which is more than 9 months old. Please consider creating a new thread instead.

    So I'm creating a new thread.

    I've got this function that shows and hides a TR with-in my TABLE, but the text never changes when you click it,
    I would like default to be hidden, and if clicked, change text to Show and show TR.

    HTML
    Code:
    <table border="1" width="100%">
    	<tr>
    		<td><div onClick="ShowHidden('ShowInfo', this);">Show / Hide Information</div></td>
    	</tr>
    	<tr class="ShowInfo" style="display:none">
    		<td>{$Information}</td>
    	</tr>
    </table>
    Javascript
    Code:
    function ShowHidden(cl, obj)
    {
    	var tbl=obj;
    	while(tbl.tagName!='TABLE') { tbl=tbl.parentNode; }
    	for (i=0; i< tbl.rows.length; i++)
    	{
    		if (tbl.rows[i].className==cl)
    		{
    			if (tbl.rows[i].style.display=='')
    			{
    				tbl.rows[i].style.display = 'none';
    			}
    			else {
    				tbl.rows[i].style.display = '';
    			}
    		}
    	}
    }

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    How about something like the following?

    Code HTML4Strict:
    <td><div onClick="ShowHidden('ShowInfo', this);">Show</div></td>

    And update the name like this.

    Code JavaScript:
    . . .
    if (tbl.rows[i].style.display=='')
    {
    	tbl.rows[i].style.display = 'none';
    	obj.firstChild.nodeValue = 'Show';
    }
    else {
    	tbl.rows[i].style.display = '';
    	obj.firstChild.nodeValue = 'Hide';
    }
    . . .

  3. #3
    SitePoint Member
    Join Date
    Aug 2004
    Location
    Atlanta
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks pmw57,
    I tried something like that before and it didn't work for me.
    But this did the trick,

    Thanks so much!


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
  •