This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes JSP and the fly likes Options in drop-down menu Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Options in drop-down menu" Watch "Options in drop-down menu" New topic

Options in drop-down menu

Krish Pat
Ranch Hand

Joined: Jul 31, 2002
Posts: 32
Hello all,
I have a drop-down menu in my program which gives a list of options. I would also want to present the user the choice of typing in their option if they already know their option.Is there some way that the user can either select one of the options from the drop-down menu OR type in his own option in the same box?
Thanks in advance,
Jyothi Lature
Ranch Hand

Joined: Oct 31, 2001
Posts: 60
Hi krish,
I ont think there is any combo box kinda component in HTMl. But we can simulate it using a text box and a drop down menu. The following code is an example code that i tried out, which will add item to the drop down menu, when the user enters a text and press tab..
<script language="JavaScript">
function addItem() {
with (document.formtest) {
var strText = textitem.value;
if (strText.length > 0) {
var nLength = listitems.options.length;
listitems.options[nLength] = new Option(strText, nLength, false, false);
textitem.value = "";
listitems.options[listitems.options.length-1].selected = true;
<body><form name="formtest">
<input type="text" name="textitem" size="14"><br>
<select name="listitems" onfocus="javascript:addItem()">
<option value="1">Existing Item 1
<option value="2">Existing Item 2
<option value="3">Existing Item 3
Hope this will be of some use to you

Jyothi<br />Sun Certified Java Programmer<br />Brainbench Certified for Javascript
Krish Pat
Ranch Hand

Joined: Jul 31, 2002
Posts: 32
Thanks Jyothi,
Suppose in a drop-box we have the options A-D, E-L, M-S. Choosing, say option "A-D" brings a table which contains the data fields which contains "A,B,C,D". What if instead of selecting the range "A-D", I want to type in, say "B" to display just the data fields which contain "B" only and neglecting "A,C,D".How do I go about it in the same box? i.e, be able to select a range "A-D" as also just type in "B".I am trying to add this feature to enhance search capabilities in my web-page.
I agree. Here's the link:
subject: Options in drop-down menu
It's not a secret anymore!