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

JavaScript Combo Box.. anyone help ?

Status
Not open for further replies.

dalvin200

Programmer
Oct 10, 2000
20
GB
Hi there..
I'm new to this JavaScript game, and I need your help.

What I have is a combo box (drop down list with input)..
The list contains the following text :

<blank space>
A - Apple
B - Banana
C - Cherry

the values for each list item are ' ', 'A', 'B' and 'C' respectivly (clever eh ? hehe).

Now the tricky part.. the user can either select an item from the list, eg clicks the DDL and selects 'B - Banana' which is fine.. BUT, what i want to do is, the user can also TYPE in a value - ie, 'B' and when the focus is lost, some kind of fucntion will search thru the list and replace 'B' with the list item 'B - Banana'.

Is this possible ?

Please help... i just know i have to use the onBlur() event right ? but what function would i need to search through the list. The list looks like this in debug mode :
&quot; = ¬A - Apple=A¬B - Banana=B¬C - Cherry=C&quot;

Thank you.
 
I have a very beta DHTML combo box you can use... otherwise, to search through the array I would do it like this (though I'm sure there is a better way of doing it):

Use the onkeyup event and use the following method:

function ComboBox_handleKey()
{
var opart
var astr = txtbox.value
var alen = astr.length
var opln = slctbox.options.length
for(var i=0;i<opln;i++)
{
opart=slctbox.options.substring(0,alen)
if(astr==opart){slctbox.value=slctbox.options}
}
}

haven't tested that code, but it should give you the basic idea jared@aauser.com
 
ahh yea.. ait.. i got it sorted, but thanks very much anyway :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top