473,756 Members | 3,051 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hide Content in a table on click of a radio button or checkbox

Basically, ive got information in a table for the layout purposes, as
its text for a questionnaire

What i Need, is for instance when the user click a radio button, that
information can be hidden.

I tried

<div id="myarea" style="visibili ty:hidden"><STR ONG><font
color="#4475AA" Question 2:</font></STRONG></divetc

and that works.

but as soon as i try and have a few things with the id myarea so i can
hide text, textareas, images etc within that, it will only hide or show
one item when i do:

<input type=radio name=mytest value=mytest3
onClick='docume nt.getElementBy Id("myarea").st yle.visibility =
"visible";' I disagree </input><br>

etc.

I foolishly tried putting that div at the start of my table cells, and
at the end of that question, but that just died. Any ideas please?

Jul 5 '06 #1
2 3493
The only solution I have found, is to put a table within a table cell.
That way the inner table can sit within a <divwhich i can hide.

This does what is needed, but then im left with a space in my page when
the table is not visible. Is there a way to have all questions close
together, and then if a user presses the button, the other table will
be visible, and the questions below it will move down?

Thanks
Advo wrote:
Basically, ive got information in a table for the layout purposes, as
its text for a questionnaire

What i Need, is for instance when the user click a radio button, that
information can be hidden.

I tried

<div id="myarea" style="visibili ty:hidden"><STR ONG><font
color="#4475AA" Question 2:</font></STRONG></divetc

and that works.

but as soon as i try and have a few things with the id myarea so i can
hide text, textareas, images etc within that, it will only hide or show
one item when i do:

<input type=radio name=mytest value=mytest3
onClick='docume nt.getElementBy Id("myarea").st yle.visibility =
"visible";' I disagree </input><br>

etc.

I foolishly tried putting that div at the start of my table cells, and
at the end of that question, but that just died. Any ideas please?
Jul 5 '06 #2

Advo wrote:
Basically, ive got information in a table for the layout purposes, as
its text for a questionnaire

What i Need, is for instance when the user click a radio button, that
information can be hidden.

I tried

<div id="myarea" style="visibili ty:hidden"><STR ONG><font
color="#4475AA" Question 2:</font></STRONG></divetc

and that works.

but as soon as i try and have a few things with the id myarea so i can
hide text, textareas, images etc within that, it will only hide or show
one item when i do:

<input type=radio name=mytest value=mytest3
onClick='docume nt.getElementBy Id("myarea").st yle.visibility =
"visible";' I disagree </input><br>
An input element has no content or end tag, it is forbidden:

<URL:http://www.w3.org/TR/html4/interact/forms.html#edef-INPUT>
It is also not a good idea to use a radio button by itself (if that's
what you are doing) as once it is checked, you can't uncheck it. A
checkbox is probably more appropriate, then toggle the visibility of
'myarea' depending on whether the checkbox is selected or not:
You might try something like:

<label for="mytest"><i nput type="checkbox" value=mytest3
name="mytest" id="mytest"
onclick="toggle Vis(this.checke d, 'myarea');"
I disagree </label>
<script type="text/javascript">

function toggleVis(val, id)
{
var el = document.getEle mentById(id);
var o;
if ( el && (o = el.style) ){
o.visibility = (val)? 'visible' : 'hidden';
}
}
</script>
However you will still have synchronisation issues in some browsers
when the page is re-loaded - the checkbox may remain checked but the
text gets hidden.

I foolishly tried putting that div at the start of my table cells, and
at the end of that question, but that just died. Any ideas please?
Your problem is likey the result of invalid HTML creating in a DOM that
is different to what you expect (and possibly different in different
browsers too). TD elements can only be children of a TR element, they
can be parents of a div. A div can't be a child (or parent) of a TR.

Your structure should be:

<div>
<table>
...
</table>
</div>

or

<table>
<tr>
<td>
<div... </div>
</td>
</tr>
</table>

Use a validator: <URL:http://validator.w3.or g/>
--
Rob

Jul 5 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
2768
by: sergio | last post by:
Hi all, I have created the following script that will show/hide a menu based on checkboxes. It works fine in Opera but not on IE6! Does anybody knows a workaround this problem? Thanks for your response. Sergio ------------------------------------------------ <script language="JavaScript" type="text/javascript">
10
13459
by: DettCom | last post by:
Hello, I would like to be able to display or hide fields based on whether a specific Yes/No radio button is selected. This is in conjunction with a posting a just made here in the same group related to checkboxes. Thanks!!!
5
2180
by: Zambien | last post by:
Hi all, Here's my problem. I have tables that are using the menu/submenu idea for hiding rows. This works fine in IE (of course) and does show/hide correctly in netscape, but as soon as the shown method is called, the table gets skewed and the presentation of the data on the page goes horribly wrong. I don't think this is a table issue as I have spent alot of time staring at this code. Here is the html...
12
2772
by: ATS | last post by:
I need to hide/reveal parts of a web page using javascript. I think I can do with using the <span> tag, but I've been away from it for a while and don't remember. Any pointers, examples?
2
12190
by: MOHSEN KASHANI | last post by:
Hi, I am trying to hide some form elements in a form by default and show/hide depending on which radio button is clicked. This is what I have but it is not working: <head> <style> ..noshow { display: none; }
1
16757
by: asilverpeach | last post by:
Hey Guys! Found some great scripts here on this topic but have to make to changes to the code that I can't seem to figure out. First, In the following code clicking on the headers shows the div information. I want a nested show hide element though. So when you click on "Do you have carpets to be cleaned?" Small Rooms & Medium Rooms appears (that I got working) But Then when you click on Small rooms or medium rooms i want the three lines...
3
2499
w33nie
by: w33nie | last post by:
I want to disable the text boxes, captain_name and captain_email, but only if the radio button, captain_guarantee, has NOT been checked. how do i do this? <form name="formTeamApplication" action="teams_process.php" method="post" onSubmit="validate()"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width='75'><span class='Body'>Team Name:</span></td> <td width='150'><input width="150"...
11
3196
by: bharathmngl | last post by:
now iam trying to add rows dynamically into the table when i click "ADD ROW" button. It should also have the option to delete the selected row. So Please help me to find code.... And also please tell me how to add textarea and radiobutton in to the dynamically created rows.. Here is my code; <html> <head> <title>Untitled Document</title>
5
10360
by: =?Utf-8?B?Y2hlY2tyYWlzZXJAY29tbXVuaXR5Lm5vc3BhbQ== | last post by:
I have a VS 2008 ASP.NET webform that has a reportview tag on it, accessing an .RLDC report in local report. The columns for the report are essentially: Month Item #1 Item#2 Item#3 I would like to add a checkbox or dropdown control to the .RLDC and have Item #1, Item #2, or Item #3 display conditionally based on a checkbox being clicked or a dropdown value being selected.
0
9456
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9872
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9711
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8712
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7244
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5141
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3805
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.