Solved

show/hide a <TR> with a checkBox

Posted on 2002-07-04
7
7,012 Views
Last Modified: 2012-05-04
How can I show or hide a table row depending on the status of a checkbox?

I have this - the table and form is placed in a layer <div></div>:

<table>
<tr>
<td>show/hide <input type="checkbox" name="toggle" value="1"><td>
<tr  style="display:none;" id="telTR">
<td class="dynaContent">Tel.<input type="text" name="tel" size="18">
</td>
</tr>
<table>

If I check the checkbox "toggle" the next row should be visible. If I uncheck it, the row should again disappear.

Must only work with IE 4+ NS 6

Thank you in advance
Joergen
0
Comment
Question by:jastroem
7 Comments
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 150 total points
ID: 7130173

If the rows look like this: <TR id="therow" style="display:inline">
You do the check boxes this way: <input type="checkbox" onClick="toggle('therow')"

Then the function is:

<script language="JavaScript">
<!--
   function toggle(target)
   {
      obj=(document.all) ? document.all[target] : document.getElementById(target);
      obj.style.display=(obj.style.display=='none') ? 'inline' : 'none';
   }
//-->
</script>

I only have IE5.5 and MOZ1.0 installed so don't know i fit works for NS6.  MOZ1.0 screws up the rendering, so NS6 might have a problem with it.


Cd&
0
 

Author Comment

by:jastroem
ID: 7130268
Hi

Thank you very much for the rapid - and good - solution!

Here's my testing result:

PC/IE 6 => just fine
PC / NS 6.2 => fine, but additional empty rows are added if the toggle button is used several times

Mac/IE 5 => just fine
Mac/NS 6 => doesn't work

Kind regards
Joergen
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 7130282
I was afraid NS 6 would be a problem.  MOZ1 was doing the same thing with sticking in the extra rows.  If I have some time next week I'll install 6.2 and see if I can find a way to clean it up. If I come up with something I'll post it here.

Cd&
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 7130284
Anyway, glad we could get most of it to work.  Thanks for the A. :^)

Cd&
0
 
LVL 1

Expert Comment

by:tariqf
ID: 7740408
I have tried the above code, and it works well, but can anyone tell me how I modify it so that the table row is initially hidden, and then displayed (toggled) when the box is checked?
0
 

Expert Comment

by:richardys
ID: 8332849
change the <tr> tag to this:

<TR id="therow" style="display:none">
0
 
LVL 1

Expert Comment

by:longmatch
ID: 8739502
I would like to hide and show a row in my table based upon the selected value, for example, when users select 'other' in the dropdown list, this row shows, and hide otherwise.

Your help is highly appreciated

Longmatch
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now