473,394 Members | 1,810 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.

searching SELECT list

This script works well for searching thru a SELECT list but doesnt work so
well with the MULTIPLE option. I need to modify it to work for a SELECT
MULTIPLE but I have no idea where to begin, any tips?
<script>

var searchString = "";

function clearSearchString() {
searchString = "";
}

function betterSelect(selectName, formName) {
// Get the keypress from the select box
var keyCode = event.keyCode;
var keyChar = String.fromCharCode(keyCode).toLowerCase();
var selectBox = eval("document." + formName + "." + selectName);
var optionsCount = selectBox.options.length;
var i;

// Check to see if the keypress is something we should care about...

if ((keyCode == "8") || (keyCode == "46"))

// Delete or backspace decrement the searchString
searchString = searchString.slice(0,-1);
} else if ((keyCode == "38") || (keyCode == "37")) {
// Up or left arrow move to the preceeding item in options list
if (selectBox.selectedIndex > 0) {
selectBox.selectedIndex --; }
return false;
} else if ((keyCode == "40") || (keyCode == "39")) {
// Down or right arrow move to the next item in the options list
if (selectBox.selectedIndex < (optionsCount - 1)) {
selectBox.selectedIndex ++; }
return false;
} else if (keyCode == "27") {
// Escape clears the searchString variable
searchString = "";
window.status = "";
return false;
} else if (keyCode == "188") {
// Comma dealt with manually
searchString = searchString + ",";
} else

// Add the new keypress to the searchString variable (default)
searchString = searchString + keyChar;
}

// Display keypresses in the status bar at the bottom of the window

var statusDisplay = searchString.toUpperCase();
window.status = "Narrowing select menu items (press 'Esc' to clear): " +
statusDisplay;

// Advance to the selected item

for(i = 0 ; i < optionsCount; i++) {
var optionItem = selectBox.options[i].text;

// Uncomment this routine to selectively exclude portions of a substring
(e.g. commas, etc.)
/* var findComma = optionItem.indexOf(", ");
if (findComma != -1) {
optionItem = optionItem.substr(0, findComma) +
optionItem.substr(findComma + 2, optionItem.length);
} */

var optionItemSubString =
optionItem.substring(0,searchString.length).toLowe rCase();

// Check each option item for text like the current searchString
if (optionItemSubString == searchString) {
// If there is a match, select that item and exit loop
selectBox.options[i].selected = true;
break;
}
}
}

</script>

<FORM ACTION="" METHOD="POST" NAME="summary">

<select name="Customer_Name" onkeydown="return false;"
onkeyup="betterSelect('Customer_Name', 'summary');"
onclick="clearSearchString(); window.status = '';" size="1" >
<option>aaa</option>
<option>bbbb</option>
<option>cc</option>
<option>abc</option>
<option>123</option>
</select>

</FORM>


Jul 20 '05 #1
1 6130
In article <bi**********@news.tdl.com>, "Adrian" <ad****@nocrapplease.ascc.com>
writes:
This script works well for searching thru a SELECT list but doesnt work so
well with the MULTIPLE option. I need to modify it to work for a SELECT
MULTIPLE but I have no idea where to begin, any tips?
In which browser? IE alerts me that event is undefined.
Mozilla tells me event is undefined in the Javascript Console. Although it does
go ahead and take me to the key I pressed (within reason, typing aaa took me to
abc, not to aaa).
if ((keyCode == "8") || (keyCode == "46"))

// Delete or backspace decrement the searchString
searchString = searchString.slice(0,-1);


Just a sidenote:
The delete key and the backspace key do totally different things. Backspace
removes the character prior to cursor position, delete removes the character
after the current cursor position.

MySearch<backspace>String
results in MySearcString
MySearch<delete>String
results in MySearchtring

Nothing to do with your original problem. Just something I noticed in scanning
the code.
--
Randy
All code posted is dependent upon the viewing browser
supporting the methods called, and Javascript being enabled.
Jul 20 '05 #2

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

Similar topics

3
by: aaj | last post by:
This is a simple question compared to some of the stuff that gets asked (and answered) here, but sometimes its easy to over look the simpler things. I've been working with databases for a few...
2
by: Tim Pollard | last post by:
Hi I'm hoping someone can help me with an access problem I just can't get my head around. I normally use access as a back end for asp pages, just to hold data in tables, so queries within access...
33
by: Geoff Jones | last post by:
Hiya I have a DataTable containing thousands of records. Each record has a primary key field called "ID" and another field called "PRODUCT" I want to retrieve the rows that satisy the following...
7
by: pbd22 | last post by:
Hi. I am somewhat new to this and would like some advice. I want to search my xml file using "keyword" search and return results based on "proximity matching" - in other words, since the search...
1
by: morangi | last post by:
<?php session_start(); error_reporting(E_ERROR && ~E_NOTICE && ~E_WARNING); ob_start(); $link = mysql_connect('localhost', 'root', 'test'); if (!$link) { die('Could not connect: ' ....
5
by: sree078 | last post by:
Hi I've a list of Values with varchar field in main in a table. I wanted to have fast search as there are very less insertions/updations. Thought to do a FullText Searching on that varchar field....
12
by: Alexnb | last post by:
This is similar to my last post, but a little different. Here is what I would like to do. Lets say I have a text file. The contents look like this, only there is A LOT of the same thing. () A...
20
by: tkip | last post by:
Hello everyone. I have been working on this DB for quite some time and still can't figure out a way to do what I want to do. It's a database that keep track of drawings and engineering change etc....
4
by: aaronkmar | last post by:
Hello Bytes, I hope this post finds you well on this wonderful Friday! I've been kicking this code around for over a week now and cannot seem to find the correct syntax to handle all of the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.