Question in dropdpown list<select> tag?

Javascript coding ..

Moderators: macek, egami, gesf

trestian
New php-forum User
New php-forum User
Posts: 51
Joined: Wed Jan 25, 2006 6:24 pm
Location: Philippines,Davao City
Contact:

Question in dropdpown list<select> tag?

Postby trestian » Mon Feb 13, 2006 2:09 am

Good day?

Can every one help me how to make this dropdown list in javascript?

Scenario

I have a dropdownlist. list are below

-Philippines
-hungary
-davao
-italy

when i type p in will go to (philipinnes) in the second letter h it will go to hungary.
there is anything possible that when i type p 2nd letter h ..that it will search the whole text..example i type phi it will go to philippines?

thanks

User avatar
revq
New php-forum User
New php-forum User
Posts: 21
Joined: Mon Feb 13, 2006 1:54 am
Location: South Africa
Contact:

Postby revq » Tue Feb 14, 2006 12:48 am

There is no easy way to do this with standard html drop downs. A previous company I was at did something like this, by having a text box, with a floating div underneath containing a list box, not a drop down - it looked something like a normal select box. Then they had code in the onchange event for the text box that would use it's value to loop through the values in the list box until it found a match and leave the first match found highlighted. In effect this allows stacking the letters to filter the list by, but it is not the most straight forward implementation to accomplish.

trestian
New php-forum User
New php-forum User
Posts: 51
Joined: Wed Jan 25, 2006 6:24 pm
Location: Philippines,Davao City
Contact:

Postby trestian » Tue Feb 14, 2006 6:14 pm

thanks revq..


now im trying to do that... that i have a text box.. wher the user will input then match the type word in the dropdown list... im also thinking that you have an idea how to used it in the java script? I have try but not works... im idea is put it in the array. when user press p it it will wil get the value in the dropdown and put it the array and test the 2nd press letter if there in the array....

thanks revq...and more power

User avatar
revq
New php-forum User
New php-forum User
Posts: 21
Joined: Mon Feb 13, 2006 1:54 am
Location: South Africa
Contact:

Postby revq » Wed Feb 15, 2006 3:06 am

Have the elements of the list box all with the same name so that javascript can treat it as an array. In the onchange event of the text box, have a for loop that works it's way through all the elements, checking for the pattern, like this

if (str.match(/text*/))

where text is the value of the text box. When it finds a match, set that element to selected and stop processing the for loop. If the element does not match, make sure it is not selected. In that way, the list should react to multiple character input, selecting the first element that matches your requirements.


Return to “JavaScript”

Who is online

Users browsing this forum: No registered users and 0 guests