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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to "uncheck" radio buttons in dynamic form 1

Status
Not open for further replies.

ixnay5

MIS
Jan 10, 2002
68
US
hi all -

sorry the description is a little weak. let me explain.

i have a page with 6 "master" radio buttons which dynamically control a form. if you check master radio button number 1, the page displays 6 additional choices (also radio buttons...let's call them slaves). if you check master 2, the page displays only 5 slaves, if you check master 3, you get 4 slaves, if you check masters 4, 5, or 6, you get only 1 slave.

let's say the user has checked master 1 and slave 3, but then changes his/her mind and checks master 2, slave 1. if the user changes his/her mind again back to master 1, the browser refreshes with slave 3 checked! and if the user then changes master 2, the browser refreshes with slave 1 checked.

i need it to stop doing this.

how do i get it to display a fresh set of unchecked slaves each time a master is checked, whether it's been checked before or not.

thx!
 
How dynamic is this form? (is it generated through a server side language?)

In any case, I would recommend putting a <div> below the three master radio buttons, and set 3 string variables to the html used to render the slave radios.

then, when a master is clicked, set the div.innerHTML to the appropriate string variable.

I can be more specific if you post some code...

 
thx nevermoor,

here's the pertinent javascript in the page head:

<script language="Javascript">
function DS31() {
DS31Div.style.visibility='visible';
DS32Div.style.visibility='hidden';
DS33Div.style.visibility='hidden';
DS34Div.style.visibility='hidden';
DS35Div.style.visibility='hidden';
DS36Div.style.visibility='hidden';

}
function DS32() {
DS31Div.style.visibility='hidden';
DS32Div.style.visibility='visible';
DS33Div.style.visibility='hidden';
DS34Div.style.visibility='hidden';
DS35Div.style.visibility='hidden';
DS36Div.style.visibility='hidden';

}
.
.
.
function capcheck(voc) {


for (var i = 0; i < mainform.length; i++) {

var cap = mainform.elements;

if (cap.name == "cap" && cap.checked == true) {


switch (parseInt(cap.value)) {

case 1:

switch(parseInt(voc.value)) {
case 1:
mainform.pcount.value="672"
mainform.scount.value="3"
break;
case 2:
mainform.pcount.value="672"
mainform.scount.value="5"
break;
case 3:
mainform.pcount.value="672"
mainform.scount.value="7"
break;
case 4:
mainform.pcount.value="672"
mainform.scount.value="14"
break;
default:
mainform.pcount.value=""
mainform.scount.value=""
break;
}

break;

case 2:


switch(parseInt(voc.value)) {
case 1:
mainform.pcount.value="1344"
mainform.scount.value="5"
break;
case 2:
mainform.pcount.value="1344"
mainform.scount.value="10"
break;
case 3:
mainform.pcount.value="1344"
mainform.scount.value="14"
break;
default:
mainform.pcount.value=""
mainform.scount.value=""
break;
}

break;
.
.
.
.
.
</script>

here's the pertinent form code in the body:

<form name="mainform">

Capacity (DS3): nbsp;&nbsp;
1:&nbsp;<input type="radio" name="cap" value="1" onclick="DS31();">
2:&nbsp;<input type="radio" name="cap" value="2" onclick="DS32();">
3:&nbsp;<input type="radio" name="cap" value="3" onclick="DS33();">
4:&nbsp;<input type="radio" name="cap" value="4" onclick="DS34();">
5:&nbsp;<input type="radio" name="cap" value="5" onclick="DS35();">
6:&nbsp;<input type="radio" name="cap" value="6" onclick="DS36();">

<DIV ID="DS31Div" style="visibility:hidden;position:absolute;top:100;left:10" >
<LABEL FOR="DS31">
<br><br>
Vocoder Suite:<br>
G.711:&nbsp;<input type="radio" name="vocds31" value="1" onclick="capcheck(this);"><br>
G.711,G.726&nbsp;<input type="radio" name="vocds31" value="2" onclick="capcheck(this);"><br>
G.711,G.726,G.729A:&nbsp;<input type="radio" name="vocds31" value="3" onclick="capcheck(this);"><br>
G.711,G.726,G.729A,G.729E;:&nbsp;<input type="radio" name="vocds31" value="4" onclick="capcheck(this);">
</LABEL>
</DIV>

<DIV ID="DS32Div" style="visibility:hidden;position:absolute;top:100;left:10">
<LABEL FOR="DS32">
<br><br>
Vocoder Suite:<br>
G.711:&nbsp;<input type="radio" name="vocds32" value="1" onclick="capcheck(this);"><br>
G.711,G.726&nbsp;<input type="radio" name="vocds32" value="2" onclick="capcheck(this);"><br>
G.711,G.726,G.729A:&nbsp;<input type="radio" name="vocds32" value="3" onclick="capcheck(this);"><br>
</LABEL>
</DIV>
.
.
.
<DIV ID="PortDiv" style="visibility:visible;position:absolute;top:225;left:10">
<LABEL FOR="port">
<br><br>
Ports:&nbsp;
<input type="text" name="pcount" size="6" readonly><br>
</LABEL>
</DIV>


<DIV ID="SimDiv" style="visibility:visible;position:absolute;top:300;left:10">
<LABEL FOR="sim">
<br><br>
SIMs/VPM:&nbsp;
<input type="text" name="scount" size="4" readonly><br>
</LABEL>
</DIV>
.
.
.

nevermind where i said clicking master 1 gets 6 slaves...master 1 delivers 4 slaves, master 2 delivers 3...starting with 4 there's only 1...but this isn't relevant.


you can see chosing a master simply makes the appropriate div visible. no slave comes in checked the first time a div is displayed, but if the user checks one and then comes back to that one later, the slave chosen the first time comes in checked.....
 
what i would do instead of having all those divs, is make one dive, say "slaveDIV" and

have multiple javascript strings, i.e.

DS31STR = "<LABEL FOR=\"DS31\">
<br><br>
Vocoder Suite:<br>
G.711:&nbsp;<input type=\"radio\" name=\"vocds31\" value=\"1\" onclick=\"capcheck(this);\"><br>
G.711,G.726&nbsp;<input type=\"radio\" name=\"vocds31\" value=\"2\" onclick=\"capcheck(this);\"><br>
G.711,G.726,G.729A:&nbsp;<input type=\"radio\" name=\"vocds31\" value=\"3\" onclick=\"capcheck(this);\"><br>
G.711,G.726,G.729A,G.729E;:&nbsp;<input type=\"radio\" name=\"vocds31\" value=\"4\" onclick=\"capcheck(this);\">
</LABEL>";

then, change the following function to:
function DS31() {
slaveDIV.innerHTML = DS31STR;
}

that way it always loads the slaves fresh...
 
thx nevermoor. you're correct. using the javascript strings as you have shown me enables the div load fresh.

thx again!
 
ahem...using the javascript strings as you have shown me enables the div TO load fresh EACH TIME.
 
well... how do you know when the sub radios are supposed to be checked? (I assumed you wanted them fresh each time) Once you have loaded a string, you can use javascript to parse the radios and check them, or you could use a server side language to read from a database and alter the strings based upon DB settings...

Let me know how it is designed to work...
 
sorry for any confusion mate. i do want them fresh each time, and so your answer was what i needed. thanks.

my second response "ahem...blah blah blah" was just to correct the crappy english in my prior message.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top