473,387 Members | 3,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,387 software developers and data experts.

Search select list?

I have been TRYING for a few days to get a *working* search of a select
list (about 800 options in list). I have not found one that works for
IE6.

Here is what I *last* tried. I would appreciate any help to get me
through this. Thank you.

function searchList(textInput) {
var carrier_list = document.carrRequestForm.carrierList;
for (i = 0; i < carrier_list.length; i++) {
if (carrier_list[i].indexOf(textInput.value) == 0) {
carrier_list.selectedIndex = i;
break;
}
}
}
Then in body..

<form action="process_Carrier_Request_Form.asp?..etc.." method="post"
name="carrRequestForm">

Quick Carrier Search: <br />
<input type="text" id="search" onkeyup="searchList(this)"/><br />

<select size="19" id="carrierList">
<%=carrier_name%> <!-- list of 800 carriers -->
</select>
<br />
<input class="frmButton" type="submit" value="Select Carrier and Close
Window"/><br />

</form>

Jun 22 '06 #1
1 8482
jo********@gmail.com wrote:
I have been TRYING for a few days to get a *working* search of a select
list (about 800 options in list). I have not found one that works for
IE6.
I think a number have been posted here.

Here is what I *last* tried. I would appreciate any help to get me
through this. Thank you.

function searchList(textInput) {
var carrier_list = document.carrRequestForm.carrierList;
for (i = 0; i < carrier_list.length; i++) {
You should keep i local, letting counters slip into the global space can
cause serious problems.

If you have 800 options, it will be more efficient to get the length
once and store it rather than looking it up (potentially) 800 times:

for (var i=0, len=carrier_list.length; i<len; i++) {

if (carrier_list[i].indexOf(textInput.value) == 0) {
carrier_list[i] will return an option element. It doesn't have an
indexOf() method, so you should get an error here.

However, the *value* of the option is a string, and you can use
indexOf() with that, so:

if ( carrier_list[i].value.indexOf(textInput.value) == 0) {
will return true if textInput matches the start of the value (or all of it).
carrier_list.selectedIndex = i;
break;


I don't like 'break', just return.
<script type="text/javascript">

function searchList(el)
{
var txt = el.form.elements['text_0'].value;
var opts = el.form.elements['sel_A'].options;
var t;

for (var i=0, len=opts.length; i<len; ++i){
t = opts[i];
if ( t.value.indexOf(txt) == 0){
t.selected = true;
return;
}
}
}

</script>

<form action="">
<div>
<select name="sel_A">

<!-- For testing to create 100 options -->
<script type="text/javascript">
var t = '';
for (var i=0; i<100; i++){
t += '<option value="' + i + '">' + i;
}
document.write(t);
</script>

</select>
<input type="text" id="text_0">
<input type="button" value="Select..."
onclick="searchList(this);">
</div>
</form>

--
Rob
Jun 22 '06 #2

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

Similar topics

19
by: William Wisnieski | last post by:
Hello Everyone, I have a main form with a datasheet subform that I use to query by form. After the user selects two criteria on the main form and clicks the cmdShowResults button on the main...
4
by: Ian Richardson | last post by:
Hi, The function I've put together below is a rough idea to extend a SELECT list, starting from: <body> <form name="bambam"> <select id="fred"> <option value="1">1</option> <option...
2
by: sathyashrayan | last post by:
Dear group, I have a task where I have to fetch datas from mysql and display it in the multiple select list box. I have fetched the datas and it is getting diplayed correctly in the multiple...
1
by: jimjack145 | last post by:
Hi All, I have one form with two multi select list box. I want to create query when user select value from it and click for result page. However i search on net but not find any code example....
11
by: woodey2002 | last post by:
This problem is driving me crazy. Hello there, i am trying to create a search form for records in my access database. The search form will contain text boxes and a multi select list box. The user...
2
by: woodey2002 | last post by:
Hi Guys and thanks for your time. I have a search form for my database that allows users to select multiple criteria from multi select list boxes. I successfully integrated a multi select...
6
by: woodey2002 | last post by:
Hi Everyone. Thanks for your time. I am trying to create a search form that will allow users to select criteria from multiple multi select boxes. So far i have managed to achieve a search option...
1
by: woodey2002 | last post by:
Hi Everyone and many thanks for your time.. I am trying to begin access and a bit of VBA i am enjoying it but I have a annoying problem I just can’t get any where on. My databse mostly includes...
6
by: ladycyradis | last post by:
I have a bit of a problem with some code in an Access 2003 database that I’m hoping someone can help me with. (If my code seems a little disjointed, it's because it is mostly copied from other...
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:
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
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:
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...

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.