Solved

show/hide a <TR> with a checkBox

Posted on 2002-07-04
7
7,069 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

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. …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

696 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