We help IT Professionals succeed at work.

Editable Combo Box

koushik111300
on
Hi, I just want to have a combo box that can be edited. i.e., my objective here is that I can allow the users either to choose the values from the list/combo box, if the user is not satisfied with the listed values he can type down his own values there. How can I achieve this with Javascript. Can I have a piece of code to achieve this.

bye
Comment
Watch Question

IT Expert
SILVER EXPERT
Top Expert 2009
Commented:
There is no such thing in html/javascript - java can do one...

I prefer this method:

<form>
<!-- Add an option
     Copyright (c) 1999-2001
     Michel Plungjan michel@irt.org -->
<select
onChange="if (this.options[this.selectedIndex].value=='add')
this.options.length++;
val = prompt('New option?','');
if (val) {
   this.options[this.options.length-2]= new Option(val,val);
   this.options[this.options.length-1]= new Option('add','add');  
   this.selectedIndex = this.options.length-2;
}">
<option value="">Please select</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="add">add</option>
</select>

</form>
Michel PlungjanIT Expert
SILVER EXPERT
Top Expert 2009

Commented:
PS: 20 points?

Author

Commented:
great

Explore More ContentExplore courses, solutions, and other research materials related to this topic.