faqts : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

9 of 12 people (75%) answered Yes
Recently 7 of 10 people (70%) answered Yes


How can I turn a table on/off within a form with a simple checkbox?

Apr 7th, 2008 23:16
ha mo, Colin Fraser, David Boosamra,

There are two ways of doing this. 
Firstly the hard way, which involves a lot of coding that can and often
does go wrong making a mess of the essential practice of making tables
dynamic. I do not recommend this way, it is a painful exercise and can
be soul destroying. 
The other is simple, effective, create a layer, then with the table in
the layer show or hide the layer. I have used buttons here, but the same
principles will apply using a checkbox, (I just did not have the time or
 will to write it all out for you. BTW, this is set up for Internet
Explorer, I am not sure what Netscape is doing with layers these days,
and unfortunately, I no longer use it at work, so everything is set for
IE these days.  
function show(id) {
	document.all[id].style.visibility = "visible" 
function hide(id) {
	document.all[id].style.visibility = "hidden"
<div id="div1" style="visibility:visible">
<table border=1>
<tr><td>Table</td><td>Hiding</td><td>and Showing</tr>
<input type="button" value = "Hide" onClick="hide('div1')">
<input type="button" value = "Show" onClick="show('div1')">