Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hide/unhide table rows

Status
Not open for further replies.

JasonHampson

Technical User
Feb 20, 2003
16
GB
I have this piece of JavaScript (Below), which is called from a html page to hide or unhide a row below the one where the script is called from (if that makes sense). I want to adapt the code so it will go through the document and hide/unhide any row that contains a certain value. Is this modification possible?

CODE[

HTML:

<div class=&quot;SmallLink&quot;>
<xsl:attribute name=&quot;onclick&quot;>onExpandTable()</xsl:attribute>
<xsl:attribute name=&quot;onmouseover&quot;>this.className='SmallLinkOver'</xsl:attribute>
<xsl:attribute name=&quot;onmouseout&quot;>this.className='SmallLink'</xsl:attribute>
[View Links]
</div>

JavaScript:


function reportError(e)
{
if (e instanceof Error)
window.alert(&quot;Caught exception : &quot; + e.description);
else
window.alert(&quot;Caught exception &quot; + e);
}

function onExpandTable(clickAction)
{
expandTable(window.event.srcElement);
window.event.cancelBubble = true;
window.event.returnValue = false;
}

function expandTable(treeNode, makeVisible)
{
try {
var parentTable = treeNode.parentElement.parentElement.parentElement;
var thisRow = treeNode.parentElement.parentElement.rowIndex;

// If no makeVisible parameter was supplied, toggle visibility

if (makeVisible == null)
makeVisible = (parentTable.rows(thisRow+1).style.display == &quot;none&quot;);

treeNode.style.color = makeVisible?(&quot;DarkBlue&quot;):(&quot;Blue&quot;)

parentTable.rows(thisRow+1).style.display = (makeVisible)?(&quot;inline&quot;):(&quot;none&quot;);
}
catch (e) {
reportError(e);
}
}
 
You could make use of a function like this:
Code:
function rowRemover( el, test_value ) {

	for( i=0; i < el.rows.length; i++ ) {

		for( j=0; j < el.rows[i].cells.length; j++ ) {

			if( el.rows[i].cells[j].firstChild.data == test_value ) {

				el.rows[i].style.visibility = &quot;hidden&quot;;				
			}
		}
	}
}

HTH.
 
Oops - I forgot you wanted either hidden or visible. Gimme a shout if you can't adapt the above on your own. :)
 
In this example you pass in a parameter element. I have multiple nested tables. Can I go through all the tables and all the rows and all the cells and the cell matching the value will hide the parent table?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top