Solved

show/hide a <TR> with a checkBox

Posted on 2002-07-04
7
7,056 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
AJAX ModalPopupExtender will Not Hide in Asp.net 1 39
Worldmap 1 28
Coding for the first time 9 70
Get Text of Select using class name ***JavaScript Only*** 3 15
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

730 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