473,800 Members | 2,507 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

help with selecting items in a list box

I have a javascript index that is similar to the one in the Windows
help. It has a text field that allows the you to type text and it
finds the closest item in the list below the text field. The list is
simply a select element with options that looks like this:

<SELECT>
<OPTION VALUE="1">A
<OPTION VALUE="2">B
<OPTION VALUE="3">C
</SELECT>

My problem is when I have a large list, the closest entry selects the
item in the list at the bottom of the list box, not the top of the
list box.

So here's the question: Is there a way to get the list box to display
the selected item and move it to the top of the list and not just find
it at the bottom?

To get an idea of what I 'want' it to look like, in Windows, go to
Help & Support (in XP it's in your start menu) and pick Index. I
basically want it to mirror that functionality.
Jul 23 '05 #1
1 1533
newcomer wrote:
I have a javascript index that is similar to the one in the Windows
help. It has a text field that allows the you to type text and it
finds the closest item in the list below the text field. So here's the question: Is there a way to get the list box to display
the selected item and move it to the top of the list and not just find
it at the bottom?

<form action="foo" onsubmit="retur n false;">
<script type="text/javascript">
document.write(
"<input type='text' name='search' onkeyup='S(this )'>"
);
</script>
<select name="list" size="3">
<option value="Batou" selected="selec ted">Batou</option>
<option value="Bormer"> Bormer</option>
<option value="Ishikawa ">Ishikawa</option>
<option value="Major">M ajor</option>
<option value="Pazu">Pa zu</option>
<option value="Tachikom a">Tachikoma </option>
<option value="Togusa"> Togusa</option>
</select>
</form>

<script type="text/javascript">
function S(oTxt){
var oSel, size, text, value;

oSel = oTxt.form.eleme nts["list"];
size = oSel.size;
text = oTxt.value.toLo werCase();

for(var ii=0, opt=oSel.option s, n=opt.length; ii<n; ii++) {
value = opt[ii].value.toLowerC ase();
if(value.indexO f(text)==0) {
opt[ii+size<n?ii+si ze:n-1].selected=true;
opt[ii].selected=true;
break;
}
}
}
</script>
Jul 23 '05 #2

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

Similar topics

3
2415
by: james.dixon | last post by:
Hi I was wondering if anyone else had had this problem before (can't find anything on the web about it). I have three select elements (list boxes - from here on I'll refer to them as 'the list boxes'). Users can add and remove items from the list boxes. When the users are adding and removing items, the list boxes are single
3
1854
by: John | last post by:
Hi there - if anyone has a few spare minutes I could really do with some help please. I'm a student and have been given an exercise using MS Access to design a simple database for a fictional furniture company. All I have to submit by Friday is an E-R diagram showing the proposed table structure. I have racked my brains to come up with an entity relationship diagram but cannot get past the stage of even selecting the entity tables to
10
10773
by: dhnriverside | last post by:
Hi guys Still having a problem with this dropdownlist. Basically, I've got 4. The first 2 work fine, then my code crashes on the 3rd. ddlEndTimeHour.Items.FindByValue(endTime).Selected = true; Where endTime is a string containing "15".
3
1305
by: Larry | last post by:
I've set up a list of image filesnames in a listview control(lvSrcFileList), I'm using the selectedIndexChange event to select which file is being displayed in a picturebox control(pbImagePreview). The first time a filename is selected it works fine but if I try to select another filename the program bombs with an exception error; flagging the line below "curntImage = Image.FromFile(cpath). The listview is set for a single selection....
3
1808
by: KatMagic | last post by:
How do you force a drop down list to default to a particular item based on its value? I have a drop down list with options Yes, No, Maybe, All, and I would like it to default to "All" This is my code, what am I doing wrong? ddlBilling.SelectedIndex = ddlBilling.Items.IndexOf(ddlBilling.Items.FindByValue("All"))
15
2585
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to determine who needs to receive the text message then send the message to the address. Only problem is, the employee may receive up to 4 of the same messages because each thread gets the recors then sends the message. I need somehow to prevent...
2
1574
by: rocksoft | last post by:
Hi I am working in asp.net with C# web application, I have used visual studio 2003, i have used dropdownlist in my application to populate the data from mysql database, i have got problem while i selected the item from dropdownlist, its not selecting correct item i'm selecting from dropdownlist, i have 64 records in my table, but i tried to work with upto 15 records it will not giving problem, when the scroll will enable to dropdownlist...
21
1897
by: tizmagik | last post by:
Database consists of the following 4 tables with respective attributes: CUSTOMER(C#, CUSTOMER NAME, ADDRESS), the key is ITEM(I#, ITEM NAME, MANUFACTURER, YEAR), the key is BOUGHT(C#, I#, DATE, QUANTITY), the key is PREFER(I#, C#), the key is I'm trying to construct the following query (in SQL)
4
2110
by: darrel | last post by:
I have a DDL list along these lines: item value="1" text="a" item value="2" text="b" item value="3" text="c" item value="2" text="d" item value="2" text="e" item value="1" text="f" item value="1" text="g"
0
10274
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10251
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10033
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
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6811
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
5469
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
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
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
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.