Trouble finding hidden table

A

avanti

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
 
D

Daz

avanti said:
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.
 
A

avanti

Thanks this helped with some other changes.
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top