Connecting Tech Pros Worldwide Forums | Help | Site Map

Adding a text box when a particular option is selected

ste33
Guest
 
Posts: n/a
#1: Nov 2 '05
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


Mick White
Guest
 
Posts: n/a
#2: Nov 3 '05

re: Adding a text box when a particular option is selected


ste33 wrote:[color=blue]
> 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.
>[/color]

http://www.mickweb.com/javascript/fo...nOnPrompt.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
ste33
Guest
 
Posts: n/a
#3: Nov 3 '05

re: Adding a text box when a particular option is selected


Thanks Mick ! Its perfect.

Stephane

Closed Thread


Similar JavaScript / Ajax / DHTML bytes