Solved

show/hide a <TR> with a checkBox

Posted on 2002-07-04
7
7,038 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

821 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