I'm trying to implement a visibility on or off function for extra inputs when a radio button that is "yes" inside a table...
it's so "Are you married?" "Yes" "No" (no is default checked)
when you hit yes I want 3 more rows like a collapse or extend feature...within the same table.
So basically what I want is the table to grow.. If you select "yes" then 3 more rows will be displayed that have other inputs available...
do I need to construct these extra rows in javascript? or can I referance some html to do something? ..I'm just kinda lost and brain farted out today I think...
any help much appreciated.
And on there you'll see the "Are you married?" question pretty close to the top..
the 3 rows after that(Spous's Name, job, b-day) are the ones I want to hide and show at will of the "Are you Married?" radio buttons.. hope that makes more sense ..
like if you click the yes button those three rows will show and if you hit no they'll collapse..
Thanks Again!
It is far easier to place the three questions in a div which you show/hide according to the radio button selection:
Code:
<form name = "myform">
Are you married? <input type = "radio" name = "rad1" onclick = "showDiv()" >Yes
<input type = "radio" name = "rad1" onclick = "showDiv()" >No
<div id = "mydiv" style="display:none">
Spouse Name <input type = "text" name = "spname"><br>
Spouse Job <input type = "text" name = "spjob"><br>
Spouse Birthday <input type = "text" name ="spbday"><br>
</div>
</form>
<script type = "text/javascript">
function showDiv() {
var f = document.myform;
f.spname.value = ""; // clear the entries if "No" selected"
f.spjob.value = "";
f.spbday.value = "";
var d = document.getElementById("mydiv");
d.style.display="none";
if (document.myform.rad1[0].checked) { // show div if "Yes" selected
d.style.display="block";
}
}
</script>
Take care. The fact that a form's control is hidden (with display:none or visibility:hidden) does not move him away from the submit query (in case you want to send data to a data base). Whenever you make a control hidden, make sure to make it disabled (and, maybe, give him back his default value). And, when make it visible again, remove its disabled property
I did exactly wut u said with the div just ended the tbody and table after the radio buttons and started a new table and tbody with the div wrapping it.. THANK YOU!
I'm dealing with some crapper coded structure (of course) so I've been editing it the best I can along the way trying to get the JS to work. FINALLY!
Take care. The fact that a form's control is hidden (with display:none or visibility:hidden) does not move him away from the submit query (in case you want to send data to a data base). Whenever you make a control hidden, make sure to make it disabled (and, maybe, give him back his default value). And, when make it visible again, remove its disabled property
Why bother to disable the form fields if they are hidden? Rather do what I have suggested and switch to the default values of "" if the user changes his radio button selection to "no".
Why bother to disable the form fields if they are hidden? Rather do what I have suggested and switch to the default values of "" if the user changes his radio button selection to "no".
And what about if some radio buttons are to be hidden? Isn't it better to have a general approach for all kind of elements?