avanti wrote:
Hi,
I have some JavaScript code in an ASP page that shows or hides a table
whenever a radio button is checked or unchecked. I use the
table.style.dispay property to do this.
However, in some cases the table is hidden on page_load. So, JS cannot
find the table by ID and gives error whenever the radio button is
clicked. Is there a way to solve this in JS?
Thanks,
Avanti
I'm not entirely sure why the problem seems to be intermitent. I would
suggest you find out why the table is being hidden to start with.
What is the error you are getting?
Setting the display attribute to 'none' only hides the table from view,
not from the DOM.
Here's some code that might help. Note that the table starts out
hidden, and a reference to the table is only obtained when the 'Toggle'
span is clicked upon.
<html>
<head>
<script type="text/javascript" language="javascript">
function toggleTable()
{
var table = document.getElementById('table');
table.style.display = (table.style.display) ? '' :
'none';
}
</script>
</head>
<body>
<span onclick="toggleTable()">Toggle</span>
<table style='display: none;' id="table">
<tr>
<td>
Top Left
<td>
Top Right
<tr>
<td>
Bottom Left
<td>
Bottom Right
</table>
</body>
</html>
If you are still having problems, please post some of your code.
Best regards.
Daz.