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

Different options in listbox depending on radio buttons.

Status
Not open for further replies.

Kunda

Technical User
Apr 29, 2002
10
0
0
US
How is it possible using javascript to make the options in a dropdown select list dependant on radio buttons?
I'd like only the neuter and vasectomy methods to appear when the radio button for "male" is selected, and only the spay and tubal ligation methods to appear when "female" is selected.
I currently have them all in the one box, it's all within <pre></pre> tags.

<b>GENDER</b> <input type=radio name=gender value=male>Male <input type=radio name=gender value=female>Female
<b>DESEXED</b> <input type=radio name=desexed value=no>No <input type=radio name=desexed value=yes>Yes <select name=&quot;method&quot;><option selected value=&quot;&quot;>- Which Method? -<option value=&quot;Castration&quot;>Castration (Neutered)<option value=&quot;Vasectomy&quot;>Vasectomy<option value=&quot;Ovariohysterectomy&quot;>Ovariohysterectomy (Spayed)<option value=&quot;Tubal Ligation&quot;>Tubal Ligation</select>

I was also wondering if the dropdown list could start as invisible and appear only when &quot;Yes&quot; radio button for &quot;Desexed&quot; is clicked, and how I could make it so the &quot;Yes&quot; button wouldn't work until either &quot;male&quot; or &quot;female&quot; was selected as the gender. Thanx in advance.
 
here is a thread that details a script to do just that...

Thread216-214085

what do you think?


- spewn
 
Thanks for that, I got it exactly how I wanted it!
trying to get <span> working inside the <pre> tags without adding an extra line meant a bit of fiddling and duplication though:

<head><script language=Javascript>
function Male() {
var IntPath = document.k9.method;
document.k9.method.length = 0;
IntPath[IntPath.length] = new Option('Castration (Neutered)','0');
IntPath[IntPath.length] = new Option('Vasectomy','1');
}
function Female() {
var IntPath = document.k9.method;
document.k9.method.length = 0;
IntPath[IntPath.length] = new Option('Ovariohysterectomy (Spayed)','0');
IntPath[IntPath.length] = new Option('Tubal Ligation','1');
}
function IsDesexed() {
document.all['nds'].style.display='none';
document.all['ds'].style.display='block';
timerOne=window.setTimeout(&quot;document.k9.desexed[1].checked=true&quot;,1);
}
function NotDesexed() {
document.all['ds'].style.display='none';
document.all['nds'].style.display='block';
timerOne=window.setTimeout(&quot;document.k9.desexed[2].checked=true&quot;,1);
}
</script></head>
<body><form name=&quot;K9&quot;><pre>
<b>GENDER</b> <input type=radio name=gender value=male onClick=&quot;Male()&quot;>Male <input type=radio name=gender value=female onClick=&quot;Female()&quot;>Female
<span id=&quot;ds&quot; STYLE=&quot;display:none&quot;><b>DESEXED</b> <input type=radio name=desexed value=no onClick=&quot;NotDesexed()&quot;>No <input type=radio name=desexed value=yes>Yes <b>METHOD:</b><select name=&quot;method&quot;><option value=&quot;&quot;>- Select a Gender! -</select></span><span id=&quot;nds&quot; STYLE=&quot;display:block&quot;><b>DESEXED</b> <input type=radio name=desexed value=no>No <input type=radio name=desexed value=yes onClick=&quot;IsDesexed()&quot;>Yes</span>
</pre></form></body>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top