Hello Everyone,
I created a javascript function to show/hide element id. In the code, the detail row will be show when its header row is clicked and the detail row will be hiiden after the hyperlink is clicked.
Can you give any advice on how to show/hide the detail row whenever its header row is clicked? For example, if I clicked header row #2, it will show detail row #2 and hide detail rows #1 and #3.
Looking forward to your replies.
Thanks in advance.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">
function showHide(currElem,hide){
if(document.layers){ // Netscape 4+
dom = document.layers[currElem].style;
}else if(document.getElementById){ // Netscape 6+, gecko, IE 5+
dom = document.getElementById(currElem).style;
}else if(document.all){ // IE 4+
dom = document.all[currElem].style;
}else{ // Browser unknown; do nothing
return ;
}
if (hide==1){
if (dom.display == "" || dom.display == "inline" || dom.display == "block" || dom.display == "table-row"){
dom.display = "none";
dom.visibility = "hidden";
}
}else{
dom.display = "";
dom.visibility = "visible";
}
}
</script>
</head>
<body>
<table border="1" cellpadding="10">
<tr>
<th> </th>
<th id="r0c1">Column 1</th>
<th id="r0c2">Column 2</th>
<th id="r0c3">Column 3</th>
<th id="r0c4">Column 4</th>
</tr>
<tr id="row1" onclick="javascript:showHide('row1_1',0);" style="cursor: pointer;">
<td><b><a href="javascript:void(0);">Row 1</a></b></td>
<td id="r1c1">
<input type="text" name="textfield" /></td>
<td id="r1c2">
<input type="text" name="textfield2" /></td>
<td id="r1c3">
<input type="text" name="textfield3" /></td>
<td id="r1c4">
<input type="text" name="textfield4" /></td>
</tr>
<tr id="row1_1" style=" display:none;">
<td colspan="6">Row 1 details </td>
</tr>
<tr id="row2" onclick="javascript:showHide('row2_1',0);" style="cursor: pointer;">
<td><b><a href="javascript:void(0);">Row 2</a></b></td>
<td id="r2c1">
<input type="text" name="textfield5" /></td>
<td id="r2c2">
<input type="text" name="textfield6" /></td>
<td id="r2c3">
<input type="text" name="textfield7" /></td>
<td id="r2c4">
<input type="text" name="textfield8" /></td>
</tr>
<tr id="row2_1" style=" display:none;">
<td colspan="5">Row 2 details </td>
</tr>
<tr id="row3" onclick="javascript:showHide('row3_1',0);" style="cursor: pointer;">
<td><b><a href="javascript:void(0);">Row 3</a></b></td>
<td id="r3c1">
<input type="text" name="textfield9" /></td>
<td id="r3c2">
<input type="text" name="textfield10" /></td>
<td id="r3c3">
<input type="text" name="textfield11" /></td>
<td id="r3c4">
<input type="text" name="textfield12" /></td>
</tr>
<tr id="row3_1" style=" display:none;">
<td colspan="5">Row 3 details </td>
</tr>
</table>
</body>
</html>