IT Community - Software Programming, Web Development and Technical Support

How to show a table when click a checkbox?

This is a discussion on How to show a table when click a checkbox? within the HTML, CSS and Javascript Coding Techniques forums, part of the Web Development category; Hi buddies, I need to show a table when I click a checkbox. If I uncheck that box, table will ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > HTML, CSS and Javascript Coding Techniques

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 09-26-2007, 11:55 PM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 1,061
S.Vinothkumar is on a distinguished road
Question How to show a table when click a checkbox?

Hi buddies,

I need to show a table when I click a checkbox. If I uncheck that box, table will be hidden.

Is there any sample javascript file?
__________________
S.VinothkumaR
Behind me is infinite power,
Before me is Endless Possibility,
Around me is Boundless Opportunity,
Why should I fear!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-27-2007, 04:18 AM
krishnakumar krishnakumar is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 206
krishnakumar is on a distinguished road
Smile Re: How to show a table when click a checkbox?

Hi,

You can do as ur wish....See my coding below,

in check box tag,

Code:
onchange="check(this)"
Script file is,

Code:
function check(ctrl)
{
	//get the state of the check box
	if (ctrl.checked == true) {
		//the box is checked, so show the table
		document.all['moreInfo'].style.display = "inline";
	} else {
		//hide the table
		document.all['moreInfo'].style.display = "none";
	}
}
then you need to create the table and give it a name called "moreInfo"...eg:

Code:
<table border="0" id="moreInfo" style="display:none">
<tr>
<td>Something here</td>
</tr>
</table>
that's it...
__________________
Krishnakumar.S
Beware of Everything -that is un true; stick to the Truth shall succeed slowly but steadily
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-28-2007, 02:09 AM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 1,061
S.Vinothkumar is on a distinguished road
Smile Re: How to show a table when click a checkbox?

Thnx krishna...

It's working fine...Great help!
__________________
S.VinothkumaR
Behind me is infinite power,
Before me is Endless Possibility,
Around me is Boundless Opportunity,
Why should I fear!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-29-2007, 12:04 AM
leoraja8 leoraja8 is offline
D-Web Sr.Programmer
 
Join Date: May 2007
Posts: 194
leoraja8 is on a distinguished road
Smile Re: How to show a table when click a checkbox?

You will need if you want to make it cross-browser.


Code:
function check(ctrl)
{
    document.getElementById('moreInfo').style.display = (ctrl.checked) ? "":"none";
}
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 09-29-2007, 12:11 AM
amansundar amansundar is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 325
amansundar is on a distinguished road
Question Re: How to show a table when click a checkbox?

Wow! a great discussion.

I have a question, how would I use it multiple times on 1 page calling a different table each time..

thanks in advance!
__________________
cheers
Aman
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 10-03-2007, 08:44 AM
leoraja8 leoraja8 is offline
D-Web Sr.Programmer
 
Join Date: May 2007
Posts: 194
leoraja8 is on a distinguished road
Smile Re: How to show a table when click a checkbox?

Code:
function check(tableId, ctrl)
{
    document.getElementById(tableId).style.display = (ctrl.checked) ? "":"none";
}
...
<input type="checkbox" name="xxx" value="xxx" onclick="check('moreInfo', this)">
<input type="checkbox" name="yyy" value="yyy" onclick="check('whatever', this)">
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 10-12-2007, 07:02 AM
GDevakii GDevakii is offline
D-Web Sr.Programmer
 
Join Date: Aug 2007
Posts: 138
GDevakii is on a distinguished road
Default Re: How to show a table when click a checkbox?

<html>
<head>

<script type="text/JavaScript">

<!--
function showlaptop(theTable)
{
if (document.getElementById(theTable).style.display == 'none')
{
document.getElementById(theTable).style.display = 'block';
}
}
//-->

<!--
function hidelaptop(theTable)
{
if (document.getElementById(theTable).style.display == 'none')
{
document.getElementById(theTable).style.display = 'none';
}
else
{
document.getElementById(theTable).style.display = 'none';
}
}
//-->
</script>

</head>

<body>
<table width="206" border="0" cellpadding="0" cellspacing="0" style="width: 30% border: 0;">
<tr width="100%">
<td>
<input type="radio" name="pctype" value="desktop" onfocus="hidelaptop('laptop');return false;" checked />
<span class="linkswhite">No</span><input type="radio" name="pctype" value="laptop" onfocus="showlaptop('laptop');return true;"/>
<span class="linkswhite">Yes
</span></td>
</tr>
</table>

<br>
<div class="options">
<table border="0" cellpadding="0" cellspacing="0">
<tr id="laptop" style="display: none;">
<td class="linkswhite"><div align="left">CCJ<br>
</div></td>
<td>&nbsp;</td>
</tr>
<tr id="laptop" style="display: none;">
<td class="linkswhite">When was the CCJ Registered ? </td>
<td><input name="textfield" type="text" class="textfield"></td>
</tr>
<tr id="laptop" style="display: none;">
<td class="linkswhite">How much was the CCJ for ? </td>
<td><input name="textfield2" type="text" class="textfield"></td>
</tr>
<tr id="laptop" style="display: none;">
<td class="linkswhite">Is the CCJ Satisfied ? </td>
<td><input name="textfield3" type="text" class="textfield"></td>
</tr>
</table>
</div>

</body>
</html>
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
count the time in seconds that a checkbox is really checked itbarota HTML, CSS and Javascript Coding Techniques 1 02-13-2008 10:16 PM
What is the difference between DELETE TABLE and TRUNCATE TABLE commands in SQL Server oxygen Database Support 6 11-23-2007 06:17 AM
checkbox validation rajkumar HTML, CSS and Javascript Coding Techniques 5 11-16-2007 12:32 AM
I have multi checkbox in my form... gk_cloud PHP Programming 2 10-22-2007 06:31 AM
I am having checkbox in datagrid and treeview, while click the button i need to check kingmaker C# Programming 3 08-14-2007 09:39 AM


All times are GMT -7. The time now is 09:11 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0