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

One Radio Button, Two Select Boxes

Status
Not open for further replies.

faithful1

Programmer
Sep 27, 2002
49
US
Please forgive me if this is confusing, I am a newbie =)
I have a form that has one radio button and two select boxes.
I want the user to choose one of two options with a radio button. That will disable the opposite select box and enable the select box they chose. For example, the radio buttons will be salesperson or manager. If they choose manager, the list of managers will be enabled and the list of salespersons disabled.
Is it possible to have both select lists contain the same name? Upon submission I want any choice on the select lists to be submitted under the same variable.
 
<script>
function radioSelect(choice){
myChoice = choice.value
if (myChoice == &quot;select1&quot;){
document.myForm.select1.disabled = false
document.myForm.select2.disabled = true
}
else{
document.myForm.select1.disabled = true
document.myForm.select2.disabled = false
}
}
</script>
<form name=&quot;myForm&quot;>
<input type=radio name=&quot;radioGroup&quot; value=&quot;select1&quot; onClick=&quot;radioSelect(this)&quot;>
<input type=radio name=&quot;radioGroup&quot; value=&quot;select2&quot; onClick=&quot;radioSelect(this)&quot;>
<select name=&quot;select1&quot;>.....</select>
<select name=&quot;select2&quot;>.....</select>
 
Thank you!
Can I have both select boxes use the same name somehow.
 
I don't think that you can have both have the same name with this script, but you can write a form handler in .asp that can determine which one was used. Another option is to have both select lists populate a hidden box onChange and just use that one box....

Code:
<input type=&quot;hidden&quot; value=&quot;&quot; name=&quot;realValue&quot;>
<select name=&quot;select1&quot; onChange=&quot;document.myForm.realValue.value=this.value&quot;>
<select name=&quot;select2&quot; onChange=&quot;document.myForm.realValue.value=this.value&quot;>

You might have to experiment w/ this one a little - I'm not sure about Netscape compatibility - you may have to write a function to do this in all browsers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top