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

dropdownlist box autosearch function

3
Hi All,

I had asp page using Visual studio 2005 to develop. I had a dropdownlist box with more than hundred items list. I am looking a function which allow user to type on dropdownlist box and the dropdownlist box will automatically to search the related items.

I tried to use the JavaScript function, but it doesn’t work. Here is my JavaScript coding.
Expand|Select|Wrap|Line Numbers
  1. <SCRIPT TYPE="text/javascript">
  2. function onSelectKeyDown()
  3. {
  4.     if(window.event.keyCode == 46)
  5.         clr();
  6. }
  7. function selectKeyPress()
  8. {
  9.  
  10.     var sndr = window.event.srcElement;
  11.     var pre = this.document.all["keys"].value;
  12.     var key = window.event.keyCode;
  13.     var char = String.fromCharCode(key);
  14.  
  15.     var re = new RegExp("^" + pre + char, "i");
  16.     for(var i=0; i<sndr.options.length; i++)
  17.     {
  18.         if(re.test(sndr.options[i].text))
  19.         {
  20.             sndr.options[i].selected=true;
  21.             document.all["keys"].value += char;
  22.             window.event.returnValue = false;
  23.             break;
  24.         }
  25.     }
  26. }
  27. function clr()
  28. {
  29.     document.all["keys"].value = "";
  30. }
  31. </SCRIPT>
I also add following code in my page_load event too.
Expand|Select|Wrap|Line Numbers
  1. Me.dropdownlist.Attributes.Add("onkeypress", "return selectKeyPress();")
  2. Me.dropdownlist.Attributes.Add("onkeydown", "return selectKeydown();")
  3. Me.dropdownlist.Attributes.Add("onblur", "return clr();")
  4. Me.dropdownlist.Attributes.Add("onfocus", "return clr();")
  5.  
Can anybody help me. Many thanks.
Jun 28 '07 #1
6 4297
kenobewan
4,871 Expert 4TB
I did this on a small application once. I used a textbox which had to be an input for mine to work. The input filled out the selected text in the dropdown and was used in the form. If I remember anything else I'll let you know, but like you I used javascript. I believe there is an easier way if want to use a combobox. HTH.
Jun 29 '07 #2
Plater
7,872 Expert 4TB
Do the web versions of the controls support the auto-complete functionality the way their windows application counter parts do?
If so, the work has been done for you.
Jun 29 '07 #3
w1688
3
I thought so, however I am unable to find the autocomplete function in ASP.NET. The autocomplete function only available on VB app only. Please correct me if I am wrong.

Do the web versions of the controls support the auto-complete functionality the way their windows application counter parts do?
If so, the work has been done for you.
Jun 29 '07 #4
Frinavale
9,735 Expert Mod 8TB
I thought so, however I am unable to find the autocomplete function in ASP.NET. The autocomplete function only available on VB app only. Please correct me if I am wrong.
The auto-complete capability is a browser based...has nothing to do with ASP.NET.

If it is turned on (most of the time this is the setting by default), and you start typing into your dropDownList it will search for any word starting with the letter you typed. This is the case with all the application's I've developed so far and don't know why it wouldn't work for you as well.

On a side note, please look into placing your code in between [code] [ /code] to make things more legible. You can even specify what type of code in inside these tags by using [code=vbnet], or [code=javascript] or [code=cpp] (for C# since it isn't provided at this time).

-Frinny
Jun 29 '07 #5
w1688
3
Thanks for your quick reply. The default function on dropdownlist box will search
when I type the first character. If I keep typing, it only search the first character on the list. For example, If I had the following list in my dropdownlist box
<SELECT NAME="state">
<OPTION VALUE="AL">Alabama</OPTION>
<OPTION VALUE="AK">Alaska</OPTION>
<OPTION VALUE="AZ">Arizona</OPTION>
<OPTION VALUE="AR">Arkansas</OPTION>
<OPTION VALUE="CA">California</OPTION>
<OPTION VALUE="RI">Rhode Island</OPTION>
</SELECT>

If I type "A", it will shows up "Alabama". However if i type "A" and then type "R", the dropdownlist box will show "Rhode Island" only instead of "Arizona"

I really don't know how to turn the auto-complete function on in my dropdownlist box. Can you tell me how?

Thx.


The auto-complete capability is a browser based...has nothing to do with ASP.NET.

If it is turned on (most of the time this is the setting by default), and you start typing into your dropDownList it will search for any word starting with the letter you typed. This is the case with all the application's I've developed so far and don't know why it wouldn't work for you as well.

On a side note, please look into placing your code in between [code] [ /code] to make things more legible. You can even specify what type of code in inside these tags by using [code=vbnet], or [code=javascript] or [code=cpp] (for C# since it isn't provided at this time).

-Frinny
Jun 29 '07 #6
Frinavale
9,735 Expert Mod 8TB
Thanks for your quick reply. The default function on dropdownlist box will search
when I type the first character. If I keep typing, it only search the first character on the list.

If I type "A", it will shows up "Alabama". However if i type "A" and then type "R", the dropdownlist box will show "Rhode Island" only instead of "Arizona"

I really don't know how to turn the auto-complete function on in my dropdownlist box. Can you tell me how?

Thx.
Yeah, that was the point I was trying to make...it only finds words that start with whatever letter you typed. The auto-complete functionality is browser based, you can't turn it on with code.

For what you'd like to do it sounds like you're going to have to write a tricky bit of JavaScript like you originally were saying.

-Frinny
Jul 3 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Brennon Arnold | last post by:
I have a problem that I figured would be relatively common, but have been unable to find any information on it as of yet. I have a page that contains two DropDownList controls, with the second...
4
by: theo | last post by:
Program flow...load file,then extract the xml text tags from the file,then the number of Xml tags retrieved from the file determines the number of dropdownlist controls instanciated in the...
1
by: | last post by:
Hi All I have a form in which i build a table for a series of twenty questions, like a survey questionaire. I use the following function in a user control to create the DropdownList from the...
2
by: Sid | last post by:
Hi All, I am trying to populate a dropdown list in my Datagrid control using the OleDbDataReader, but when my function tries to add items to the dropdownlist it says that my dropdownlist...
6
by: Julius Fenata | last post by:
Dear all, I have created client-side scripting to trigger event onChange from code-behind, like this: DropDownList1.Attributes = "GenerateArticleID()"; At the script on Windows Form, I...
2
by: Marc Robitaille | last post by:
Hello, I set the DataSource property of a DropDownList to as DataSet that is filled from a SQLDataAdapter. The AutoPostBack property of that DropDownList is set to True. When the...
10
by: ads | last post by:
hi, after binding the dropdownlist to a datasource, ive experience this error "Cannot have multiple items selected in a dropdownlist" after using the code:...
1
by: glenn | last post by:
Hi folks, I need to have two ddl's in one DataGrid cell. The first ddl has a list of company names and the second has a list of contact names that work in the company name that was selected in...
3
by: Lohboy | last post by:
Using ASP.NET and IE7. (Sorry if I am posting in the wrong forum but my problem seemed to be more related to the JavaScript side than the ASP.NET side.) I have two DropDownList controls the...
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: 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
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
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.