Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question on toggling fields displayed

Status
Not open for further replies.

locoguy

Programmer
Joined
Jan 17, 2006
Messages
1
Location
US
I listed myself as a "programmer" but I'm about as much of a programmer as I am a funambulist, so...

I have a simple form with four radio buttons and six text fields. One of the radio buttons is labeled "Other." Four of the six text fields are to display in any event and are required, while the first two should only be displayed in the event "Other" is selected, in which case all six text fields are required.

I know this involves <div></div> tags and perhaps attributes such as "hidden" or "invisible," but I'm not far enough along with this stuff to put the pieces together. A schematic or generic answer would help a lot, or even a link to a handy resource -- I should be able to figure things out from there.

Thanks!
 
Something like this (only [3] is not generic).
[tt]
<html>
<head>
<script language="javascript">
function checkit(obj) {
var oradio=document.formname.elements[obj.name][3];
var oelem=document.getElementById("divid");
if (oradio.checked) {
oelem.style.display="block";
} else {
oelem.style.display="none";
//may or may not need to clear
for (var i=0;i<oelem.childNodes.length;i++) {
oelem.childNodes.value="";
}
}
}
</script>
</head>
<body>
<form name="formname">
<input name="gradio" type="radio" value="1" onclick="checkit(this)" />
<input name="gradio" type="radio" value="2" onclick="checkit(this)" />
<input name="gradio" type="radio" value="3" onclick="checkit(this)" />
<input name="gradio" type="radio" value="4" checked="checked" onclick="checkit(this)" />
<br />
<div id="divid" style="display:block;">
<input type="text" name="txt1" style="background-color:yellow" /><br />
<input type="text" name="txt2" style="background-color:yellow" /><br />
</div>
<input type="text" name="txt3" /><br />
<input type="text" name="txt4" /><br />
<input type="text" name="txt5" /><br />
<input type="text" name="txt6" /><br />
</form>
</body>
</html>
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top