473,385 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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="visibility:hidden"><STRONG><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='document.getElementById("myarea").style.v isibility =
"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 3461
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="visibility:hidden"><STRONG><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='document.getElementById("myarea").style.v isibility =
"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="visibility:hidden"><STRONG><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='document.getElementById("myarea").style.v isibility =
"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"><input type="checkbox" value=mytest3
name="mytest" id="mytest"
onclick="toggleVis(this.checked, 'myarea');"
I disagree </label>
<script type="text/javascript">

function toggleVis(val, id)
{
var el = document.getElementById(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.org/>
--
Rob

Jul 5 '06 #3

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

Similar topics

9
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...
10
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...
5
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...
12
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
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 {...
1
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...
3
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"...
11
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...
5
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 ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...

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.