473,587 Members | 2,463 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 clearSearchStri ng() {
searchString = "";
}

function betterSelect(se lectName, formName) {
// Get the keypress from the select box
var keyCode = event.keyCode;
var keyChar = String.fromChar Code(keyCode).t oLowerCase();
var selectBox = eval("document. " + formName + "." + selectName);
var optionsCount = selectBox.optio ns.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.sl ice(0,-1);
} else if ((keyCode == "38") || (keyCode == "37")) {
// Up or left arrow move to the preceeding item in options list
if (selectBox.sele ctedIndex > 0) {
selectBox.selec tedIndex --; }
return false;
} else if ((keyCode == "40") || (keyCode == "39")) {
// Down or right arrow move to the next item in the options list
if (selectBox.sele ctedIndex < (optionsCount - 1)) {
selectBox.selec tedIndex ++; }
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.to UpperCase();
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.optio ns[i].text;

// Uncomment this routine to selectively exclude portions of a substring
(e.g. commas, etc.)
/* var findComma = optionItem.inde xOf(", ");
if (findComma != -1) {
optionItem = optionItem.subs tr(0, findComma) +
optionItem.subs tr(findComma + 2, optionItem.leng th);
} */

var optionItemSubSt ring =
optionItem.subs tring(0,searchS tring.length).t oLowerCase();

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

</script>

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

<select name="Customer_ Name" onkeydown="retu rn false;"
onkeyup="better Select('Custome r_Name', 'summary');"
onclick="clearS earchString(); 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 6168
In article <bi**********@n ews.tdl.com>, "Adrian" <ad****@nocrapp lease.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.sl ice(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<backsp ace>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
1474
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 years now, but have no formal training, so some times you just get on and if it works dont worry about it. But sometimes I wonder just how it works underneath the skin e.g. If I have 100000 records in a complicated view and say each record, amongst...
2
1676
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 are a mystery to me, but I can't think of any other way of dealing with the problem. I have six tables in my db: tblCompanies (list of companies, primary key CompanyID) tblOffices (list of office buildings including what company owns/uses
33
2461
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 criteria: I have a list of about 100 numbers which correspond to the ID field and also another 40 say numbers corresponding to the numbers in the PRODUCT field. I want to show the rows that correspond to both these criteria.
7
2612
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 string will often not produce a direct match, the results will be based on proximity (50%, 20% 100%, etc). are there any good examples out there on how to do keyword searches on XML data? How should i set up my xml file so
1
1779
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: ' . mysql_error()); } if (isset($_POST))
5
1577
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. Imp Note: The name column can be a phrase too. I want to search on the key stroke from front end. so should be able to search the name column on single charater or words. declare @a varchar(10)
12
2363
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 registry mark given by underwriters (as at Lloyd's) to ships in first-class condition. Inferior grades are indicated by A 2 and A 3. () The first three letters of the alphabet, used for the whole alphabet. () In church or chapel style; -- said of...
20
2513
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. Aslo, the tables for drawings are grouped by year. I have a Main Form and on that main form, several cmd buttons to initialize sub forms are located. There are a quite a few tables and the names are quite simple. For example, for drawing that are...
4
2023
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 possible selections of my search form. Would someone please help me correct my IF statements in this code used for searching. Here's how it works.
0
7924
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8219
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8221
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5395
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3845
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2364
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1455
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1192
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.