JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 3rd, 2004, 04:19 PM
nmahdjour nmahdjour is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 10 nmahdjour User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
drop down list scrolling

Hi,

Is there a way to create a dropdownlist that enables me to browse through its items by typing in more than one letter? For instance, if there are two words "mysql" and "mssql", I'd like the selector to jump to "mysql" in case I type in "my".

Thanks,
Nima

Reply With Quote
  #2  
Old November 8th, 2004, 06:31 PM
nmahdjour nmahdjour is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 10 nmahdjour User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
found it

i found the javascript for it, see below. in addition i had to add the attribute onButtonPress="evalKey()" in the dropdownlist tag.

var tString = '';
var lsf = 0; // last successful index


function evalKey() {
// Global Variables
var i = 0;
var success = false;
var elem = event.srcElement;
var tLowElemText = '';
// Get the unicode char of the keypress
var eCode = event.keyCode;
// Check if it's a vaid ASCII Character
if (eCode == 27){
tString = '';
elem.selectedIndex = 0;
}
else if ( (eCode > 31) && (eCode < 122))
{
// Convert the Code to the corresponding character and add to searchstring
tString += String.fromCharCode(eCode);
// ... and perform the search starting from the top element in the listbox
while (success == false)
{
i = 0;
// Convert everything to lowercase; allows an easy comparison
var tLowString = tString.toLowerCase();
// Compose the regexp searchstring ...
var rExpr = eval("/^" + tLowString + "/");
while ((i < elem.length)&& (success == false) )
{
tLowElemText = elem.options[i].text.toLowerCase();
// success: Position the listbox on the (first) found element
if (tLowElemText.search(rExpr) != -1)
{
elem.selectedIndex = i;
success = true;
}
else {
i++; }
} // while i < elem.length
// if nothing is found in the entire list, the last character of the
//searchstring is removed to allow typing the correct 'next' character
if (success == false) {
tString = tString.substr(0, tString.length-1);
}
} // while success = false
}

window.event.returnValue = false;
window.event.cancelBubble = true;
}

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > drop down list scrolling


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT