I have found a little script online which has a nice expanding and collapsing TABLE effect. I am trying to build a display for a mailbox, the result will be echoed from PHP to dynamically create all the rows from a MySQL DB.
When a user clicks on a email subject 'Toggle' it should slide down to display the email where 'Test row' is.
The script works fine until echoing it. Is what I'm trying to do possible with the below script, I'm not to clued up on the JavaScript side of things so I'm not sure why it's breaking.
Any other recommendations would be appreciated.
I haven't pasted my code as I have been through to many variations(non worked).. :/
When a user clicks on a email subject 'Toggle' it should slide down to display the email where 'Test row' is.
The script works fine until echoing it. Is what I'm trying to do possible with the below script, I'm not to clued up on the JavaScript side of things so I'm not sure why it's breaking.
Any other recommendations would be appreciated.
I haven't pasted my code as I have been through to many variations(non worked).. :/
Code:
<html>
<head>
<title> New Document </title>
</head>
<body>
<table width="400">
<tbody>
<tr><td style="background-color: #CCC"><a href="#" onclick="toggleItem('myTbody')">Toggle</a></td></tr>
</tbody>
<tbody id="myTbody">
<tr><td>Test row1</td></tr>
<tr><td>Test row2</td></tr>
<tr><td>Test row3</td></tr>
<tr><td>Test row4</td></tr>
<tr><td>Test row5</td></tr>
</tbody>
</table>
</body>
</html>
<script language="javascript">
function getItem(id)
{
var itm = false;
if(document.getElementById)
itm = document.getElementById(id);
else if(document.all)
itm = document.all[id];
else if(document.layers)
itm = document.layers[id];
return itm;
}
function toggleItem(id)
{
itm = getItem(id);
if(!itm)
return false;
if(itm.style.display == 'none')
itm.style.display = '';
else
itm.style.display = 'none';
return false;
}
</script>