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

<select> where user can fill in his own value in the last option 1

Status
Not open for further replies.

Quasibobo

Programmer
Oct 11, 2001
168
NL
Hi,

I'm looking for a way to create a dropdown/select tag where the user can select some standard values or fill in his own (in the last option-field) Like 'CSS Style definition' in Dreamweaver...

Something like this:
<select name=&quot;gallons&quot;>
<option value=&quot;10&quot;>10</option>
<option value=&quot;20&quot;>20</option>
<option value=&quot;30&quot;>30</option>
<option value=&quot;40&quot;>40</option>
<option value=&quot;....?&quot;>[value]</option>
</select>

So when users select the last option they can fill in their own value...

Anyone know how to do or where to find a script like this?

Quasibobo

Don't eat yellow snow!
 
You can't quite do that, but you can right an input box that add the value to the select list and selects it - do you want the code for that?

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook
 
Mmmmh.... too bad that it isn't possible.

I think I'll just add a textfield underneath the select-box where the user can fill in his own value.

Don't eat yellow snow!
 
You could do this....

<form name=&quot;myForm&quot;>
<select name=&quot;gallons&quot; onChange=&quot;checkSelect()&quot;>
<option value=&quot;10&quot;>10</option>
<option value=&quot;20&quot;>20</option>
<option value=&quot;30&quot;>30</option>
<option value=&quot;40&quot;>40</option>
<option value=&quot;other&quot;>Other Value</option>
</select>

<script>
function checkSelect(){
for (x=0; x<document.myForm.gallons.options.length; x++){
index = document.myForm.gallons.selectedIndex
if (document.myForm.gallons.options[index].value == &quot;other&quot;){
newVal = prompt(&quot;what value&quot;)
numOptions = document.myForm.gallons.options.length
document.myForm.gallons.options[numOptions] = new Option (newVal, newVal)
document.myForm.gallons.selectedIndex = numOptions
break;
}
}
}
</script>

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook
 
Ok... thanks. Maybe I'll use it (I don't really like the javascript-prompt...)

Thanks anyway!

Quasibobo

Don't eat yellow snow!
 
I thought it was a great idea. Have a star on me.

Cheers,


[monkey] Edward [monkey]

&quot;Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!&quot; -- inventor of the cat door
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top