Adding a text box when a particular option is selected

S

ste33

Hi,

I spent the last hour or so trying to find a simple solution to this
but with no success.

I'd like to have a select box in a form where a user could select
"other" if no option is the right one. When the user chooses "other",
I'd like a text box to be automatically created or revealed so that the
user could specify what this "other" is. For example, think about a
form where a user can select his country and if the country is not in
the list, than select "other" and be presented a text box where the
country name can be entered.

I'm sure there is a simple solution to this but just couldn't find it.
I am not a javascript programmer per say and the best case scenario
would be an example that I could strongly base my implementation on..
Any help and/or pointer would be appreciated.

Thanks
 
M

Mick White

ste33 said:
Hi,

I spent the last hour or so trying to find a simple solution to this
but with no success.

I'd like to have a select box in a form where a user could select
"other" if no option is the right one. When the user chooses "other",
I'd like a text box to be automatically created or revealed so that the
user could specify what this "other" is. For example, think about a
form where a user can select his country and if the country is not in
the list, than select "other" and be presented a text box where the
country name can be entered.

I'm sure there is a simple solution to this but just couldn't find it.
I am not a javascript programmer per say and the best case scenario
would be an example that I could strongly base my implementation on..
Any help and/or pointer would be appreciated.

http://www.mickweb.com/javascript/forms/jumpmenus/newOptionOnPrompt.html
<script type="text/javascript">
function replaceOptionWithPrompt(menu,msg){
if(menu.selectedIndex==menu.length-1){
var x=window.prompt(msg,"");
if(x){
menu[menu.length-1]= new Option(x,x);
menu[menu.length-1].selected=true;
}
}
}
</script>
<select name="jobs"
onchange=
"replaceOptionWithPrompt(this,'Please supply your job description')">
<option selected>Profession</option>
<option value="doc">Doctor</option>
<option value="atty">Lawyer</option>
<option value="realtor">Real Estate</option>
<option value="other">Other</option>
</select>

Mick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top