0

Hi,

I am trying to hide a table based on its id on clicking a button.

function showTable() {


var reasonTable = document.getElementById("reasonTable");
if(reasonTable.style.display == "none")
{
reasonTable.style.display = "block";
reasonTable.style.visibility = "visible";
}
}


<form id="MyForm" method="post" name="MyForm">
<TABLE id="reasonTable" style="visibility: hidden; display: none;" WIDTH="612" CELLPADDING="0" CELLSPACING="0" ALIGN="center">
<TR>
<TD VALIGN="middle" HEIGHT="15">Value1</TD>
</TR>
<TR>
<td>
<a href="#" onclick="javascript:showTable();">submit</a>
</td>
</TR>


</table>
</form>

It is giveing null for document.getElementById("reasonTable"). Whats wrong in above code. Thanks in advance.

Edited by ~s.o.s~: formatting

4
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by Freon22
0

your javascript is not cross-browser compatible. Go get jquery - rather easy to get your head around. You can do stuff like $("#reasonTable").fadeIn();
Also, your link in the above code is apparently contained inside something hidden.

0

Try this:

<script>
function toggleTable(link) {
	var reasonTable = document.getElementById("reasonTable");
	if(reasonTable.style.display == "none") {
		reasonTable.style.display = "block";
		link.innerHTML = "Hide Table";
	}
	else {
		reasonTable.style.display = "none";
		link.innerHTML = "Show Table";
	}
	return false;//important
}
</script>
<form id="MyForm" method="post" name="MyForm">
<table id="reasonTable" style="display:none;" width="612" cellpadding="0" cellspacing="0" align="center">
<tr><td valign="middle" height="15">Value1</td></tr>
</table>
<a href="#" onclick="return toggleTable(this);">Show Table</a><!-- note "return" here -->
</form>

Airshow

0

Tried but no luck. object required error at if(reasonTable.style.display == "none") {

0

I tested Airshow example and it works good. You need to find out why the document.getElementById is not returning the object "reasonTable"

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.