473,394 Members | 1,717 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

dropdown filter

Hi All,

I've tried searching for this answer but have had no joy.
Is there anyway with javascript to allow the end user to click in a dropdown
box and when they type the first few letters it brings up the next match
rather than the first bunch of words with the last letter.
e.g.

Dropdown box :
BIRMINGHAM
BRIGHTON
BRISTOL
GLASGOW

when the user types brig brighton is displayed instead of glasgow.

Thanks in advance,
Hermes
Jul 23 '05 #1
1 4719
"Hermes" <no****@nospam.com> wrote in message
news:cl**********@sparta.btinternet.com...
Hi All,

I've tried searching for this answer but have had no joy.
Is there anyway with javascript to allow the end user to click in a dropdown box and when they type the first few letters it brings up the next match
rather than the first bunch of words with the last letter.
e.g.

Dropdown box :
BIRMINGHAM
BRIGHTON
BRISTOL
GLASGOW

when the user types brig brighton is displayed instead of glasgow.

Thanks in advance,
Hermes

Try this; watch for word-wrap.
<html>
<head>
<title>typefast.htm</title>
</head>
<body>
<script type="text/javascript">
// Cooking with JavaScript & DHTML
// Bonus Recipe: Typing select Element Choices in IE for Windows
// http://www.oreillynet.com/pub/a/java...nygoodman.html
// http://www.oreillynet.com/lpt/a/4135

// global storage object for type-ahead info, including reset() method
var typeAheadInfo = {last:0, accumString:"", delay:2000, timeout:null,
reset:function() {this.last=0; this.accumString=""}};

// function invoked by select element's onkeydown event handler
function typeAhead() {
// limit processing to IE event model supporter; don't trap Ctrl+keys
if (window.event && !window.event.ctrlKey) {
// timer for current event
var now = new Date();
// process for an empty accumString or an event within [delay] ms of
last
if (typeAheadInfo.accumString == "" || now - typeAheadInfo.last <
typeAheadInfo.delay) {
// make shortcut event object reference
var evt = window.event;
// get reference to the select element
var selectElem = evt.srcElement;
// get typed character ASCII value
var charCode = evt.keyCode;
// get the actual character, converted to uppercase
var newChar = String.fromCharCode(charCode).toUpperCase();
// append new character to accumString storage
typeAheadInfo.accumString += newChar;
// grab all select element option objects as an array
var selectOptions = selectElem.options;
// prepare local variables for use inside loop
var txt, nearest;
// look through all options for a match starting with accumString
for (var i = 0; i < selectOptions.length; i++) {
// convert each item's text to uppercase to facilitate
comparison
// (use value property if you want match to be for hidden
option value)
txt = selectOptions[i].text.toUpperCase();
// record nearest lowest index, if applicable
nearest = (typeAheadInfo.accumString > txt.substr(0,
typeAheadInfo.accumString.length)) ? i : nearest;
// process if accumString is at start of option text
if (txt.indexOf(typeAheadInfo.accumString) == 0) {
// stop any previous timeout timer
clearTimeout(typeAheadInfo.timeout);
// store current event's time in object
typeAheadInfo.last = now;
// reset typeAhead properties in [delay] ms unless cleared
beforehand
typeAheadInfo.timeout =
setTimeout("typeAheadInfo.reset()", typeAheadInfo.delay);
// visibly select the matching item
selectElem.selectedIndex = i;
// prevent default event actions and propagation
evt.cancelBubble = true;
evt.returnValue = false;
// exit function
return false;
}
}
// if a next lowest match exists, select it
if (nearest != null) {
selectElem.selectedIndex = nearest;
}
} else {
// not a desired event, so clear timeout
clearTimeout(typeAheadInfo.timeout);
}
// reset global object
typeAheadInfo.reset();
}
return true;
}
</script>
<form>
<select name="City" onkeydown="typeAhead()">
<option>
<option>BIRMINGHAM
<option>BRIGHTON
<option>BRISTOL
<option>GLASGOW
</select>
</form>
</body>
</html>
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mike O. | last post by:
MS Access 2003 "filter by form" has drop down lists that allow the user to select values for each field to filter by. However, once some values are selected,the remaining dropdown lists remain the...
1
by: Stuart Shay | last post by:
Hello All: I hava a ASP.NET Web Page where I want to change the visibility of a Dropdown, I want to avoid using Postback since the selection of the Dropdown choices is always the same. The Code...
0
by: Pablo | last post by:
Hi at all! I have a problem (what's new! :P). I have two dropDown and two ODS. The dropDown filter each other at postback. When I select an item of the first DD, it fire a postback and filter...
3
by: Cagey | last post by:
What I'm trying for: If this selection or if click on selection (highlighted line choice/ which ever selection change) w/in query's combo dropdown list box (on Switchboard), then Open in...
1
by: mwhitlatch | last post by:
I have a repeater where the data is filtered by a param in the querystring. In the repeater I have a dropdown that needs to only show the data based upon the filter I set up in the datasource. I have...
2
by: William Youngman | last post by:
We are developing an application that presents data to the user in a gridview and we are using the dropdown extender to give the user a SharePoint 2007 type dropdown menu attached to the cells of a...
0
by: pearsont74 | last post by:
ok...i have an existing html form that have a number of fields..one being a dropdown specialty list. the form does a get to an aspx datagrid written in c# (i did not write this and i need to only...
16
by: PhilippeM | last post by:
I am still very new at this (first timer actually).. I am also trying (with numerous efforts) to create a search box in a form. I have made a dropdown box and a textbox to enter the searchcriteria. I...
5
by: =?Utf-8?B?Y2hlY2tyYWlzZXJAY29tbXVuaXR5Lm5vc3BhbQ== | last post by:
I have a VS 2008 ASP.NET webform that has a reportview tag on it, accessing an .RLDC report in local report. The columns for the report are essentially: Month Item #1 Item#2 Item#3 ...
5
by: plumba | last post by:
Hi all. I have two drop down menus, the first a list of Departments, the second a list of Sections. Each Department has a set of Setions, so the Sections dropdown contains complete list of all...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.