473,748 Members | 6,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dropdown on Textbox using ASP

A P
Hi!

I have seen some techniques like this on the web. Currently, I'm using Combo
box which values came from database table. One disadvantage is when the
combo box have lots of values, users are complaining since you cannot use
keyboard to search the value that is needed. Hope you might help me.

regards,

Me
Jul 22 '05 #1
6 2718
You'll have to build your own control for that, or I would recommend a
simple SEARCH form to return the result they want

--
Curt Christianson
Site & Scripts: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"A P" <ap@textguru.ph > wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
Hi!

I have seen some techniques like this on the web. Currently, I'm using
Combo
box which values came from database table. One disadvantage is when the
combo box have lots of values, users are complaining since you cannot use
keyboard to search the value that is needed. Hope you might help me.

regards,

Me

Jul 22 '05 #2
CJM

"A P" <ap@textguru.ph > wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
Hi!

I have seen some techniques like this on the web. Currently, I'm using
Combo
box which values came from database table. One disadvantage is when the
combo box have lots of values, users are complaining since you cannot use
keyboard to search the value that is needed. Hope you might help me.

regards,

Me


Use a <Select> tag as normal, but add a couple of event handlers in as
follows:

<select name="field1" onkeypress="lis tbox_onkeypress ();"
onblur="listbox _onblur();">
<option>1</option>
...
<option>n</option>
</select>

Then bang the following script in to a .js file and link it in... and hey
presto... you have autocomplete functionality.

// Auto-select listbox

// This script and the listbox on this page illustrates one
// way to create an "auto-complete" listbox, where the

var toFind = ""; // Variable that acts as keyboard buffer
var timeoutID = ""; // Process id for timer (used when stopping
// the timeout)
timeoutInterval = 250; // Milliseconds. Shorten to cause keyboard
// buffer to be cleared faster
var timeoutCtr = 0; // Initialization of timer count down
var timeoutCtrLimit = 3 ; // Number of times to allow timer to count
// down
var oControl = ""; // Maintains a global reference to the
// control that the user is working with.

function listbox_onkeypr ess(){

// This function is called when the user presses a key while focus is in
// the listbox. It maintains the keyboard buffer.
// Each time the user presses a key, the timer is restarted.
// First, stop the previous timer; this function will restart it.
window.clearInt erval(timeoutID )

// Which control raised the event? We'll need to know which control to
// set the selection in.
oControl = window.event.sr cElement;

var keycode = window.event.ke yCode;
if(keycode >= 32 ){
// What character did the user type?
var c = String.fromChar Code(keycode);
c = c.toUpperCase() ;
// Convert it to uppercase so that comparisons don't fail
toFind += c ; // Add to the keyboard buffer
find(); // Search the listbox
timeoutID = window.setInter val("idle()", timeoutInterval );
// Restart the timer
}
}

function listbox_onblur( ){
// This function is called when the user leaves the listbox.

window.clearInt erval(timeoutID );
resetToFind();
}

function idle(){
// This function is called if the timeout expires. If this is the
// third (by default) time that the idle function has been called,
// it stops the timer and clears the keyboard buffer

timeoutCtr += 1
if(timeoutCtr > timeoutCtrLimit ){
resetToFind();
timeoutCtr = 0;
window.clearInt erval(timeoutID );
}
}

function resetToFind(){
toFind = ""
}
function find(){
// Walk through the select list looking for a match

var allOptions = document.all.it em(oControl.id) ;

for (i=0; i < allOptions.leng th; i++){
// Gets the next item from the listbox
nextOptionText = allOptions(i).t ext.toUpperCase ();

// By default, the values in the listbox and as entered by the
// user are strings. This causes a string comparison to be made,
// which is not correct for numbers (1 < 11 < 2).
// The following lines coerce numbers into an (internal) number
// format so that the subsequent comparison is done as a
// number (1 < 2 < 11).

if(!isNaN(nextO ptionText) && !isNaN(toFind) ){
nextOptionText *= 1; // coerce into number
toFind *= 1;
}

// Does the next item match exactly what the user typed?
if(toFind == nextOptionText) {
// OK, we can stop at this option. Set focus here
oControl.select edIndex = i;
window.event.re turnValue = false;
break;
}

// If the string does not match exactly, find which two entries
// it should be between.
if(i < allOptions.leng th-1){

// If we are not yet at the last listbox item, see if the
// search string comes between the current entry and the next
// one. If so, place the selection there.

lookAheadOption Text = allOptions(i+1) .text.toUpperCa se() ;
if( (toFind > nextOptionText) &&
(toFind < lookAheadOption Text) ){
oControl.select edIndex = i+1;
window.event.ca ncelBubble = true;
window.event.re turnValue = false;
break;
} // if
} // if

else{

// If we are at the end of the entries and the search string
// is still higher than the entries, select the last entry

if(toFind > nextOptionText) {
oControl.select edIndex = allOptions.leng th-1 // stick it
// at the end
window.event.ca ncelBubble = true;
window.event.re turnValue = false;
break;
} // if
} // else
} // for
} // function
Hope this helps...

Chris
Jul 22 '05 #3
Looks nice CJM.
I had written something quick for a couple of my Combos but I'll take a
close look at your functions and may just integrate it in my pages.
Of course I'll give you full credit but no paycheck. :-)
Thanks for the code.

"CJM" <cj*******@news group.nospam> wrote in message
news:OB******** ******@TK2MSFTN GP10.phx.gbl...

"A P" <ap@textguru.ph > wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
Hi!

I have seen some techniques like this on the web. Currently, I'm using
Combo
box which values came from database table. One disadvantage is when the
combo box have lots of values, users are complaining since you cannot use
keyboard to search the value that is needed. Hope you might help me.

regards,

Me


Use a <Select> tag as normal, but add a couple of event handlers in as
follows:

<select name="field1" onkeypress="lis tbox_onkeypress ();"
onblur="listbox _onblur();">
<option>1</option>
...
<option>n</option>
</select>

Then bang the following script in to a .js file and link it in... and hey
presto... you have autocomplete functionality.

// Auto-select listbox

// This script and the listbox on this page illustrates one
// way to create an "auto-complete" listbox, where the

var toFind = ""; // Variable that acts as keyboard buffer
var timeoutID = ""; // Process id for timer (used when stopping
// the timeout)
timeoutInterval = 250; // Milliseconds. Shorten to cause keyboard
// buffer to be cleared faster
var timeoutCtr = 0; // Initialization of timer count down
var timeoutCtrLimit = 3 ; // Number of times to allow timer to count
// down
var oControl = ""; // Maintains a global reference to the
// control that the user is working with.

function listbox_onkeypr ess(){

// This function is called when the user presses a key while focus is in
// the listbox. It maintains the keyboard buffer.
// Each time the user presses a key, the timer is restarted.
// First, stop the previous timer; this function will restart it.
window.clearInt erval(timeoutID )

// Which control raised the event? We'll need to know which control to
// set the selection in.
oControl = window.event.sr cElement;

var keycode = window.event.ke yCode;
if(keycode >= 32 ){
// What character did the user type?
var c = String.fromChar Code(keycode);
c = c.toUpperCase() ;
// Convert it to uppercase so that comparisons don't fail
toFind += c ; // Add to the keyboard buffer
find(); // Search the listbox
timeoutID = window.setInter val("idle()", timeoutInterval );
// Restart the timer
}
}

function listbox_onblur( ){
// This function is called when the user leaves the listbox.

window.clearInt erval(timeoutID );
resetToFind();
}

function idle(){
// This function is called if the timeout expires. If this is the
// third (by default) time that the idle function has been called,
// it stops the timer and clears the keyboard buffer

timeoutCtr += 1
if(timeoutCtr > timeoutCtrLimit ){
resetToFind();
timeoutCtr = 0;
window.clearInt erval(timeoutID );
}
}

function resetToFind(){
toFind = ""
}
function find(){
// Walk through the select list looking for a match

var allOptions = document.all.it em(oControl.id) ;

for (i=0; i < allOptions.leng th; i++){
// Gets the next item from the listbox
nextOptionText = allOptions(i).t ext.toUpperCase ();

// By default, the values in the listbox and as entered by the
// user are strings. This causes a string comparison to be made,
// which is not correct for numbers (1 < 11 < 2).
// The following lines coerce numbers into an (internal) number
// format so that the subsequent comparison is done as a
// number (1 < 2 < 11).

if(!isNaN(nextO ptionText) && !isNaN(toFind) ){
nextOptionText *= 1; // coerce into number
toFind *= 1;
}

// Does the next item match exactly what the user typed?
if(toFind == nextOptionText) {
// OK, we can stop at this option. Set focus here
oControl.select edIndex = i;
window.event.re turnValue = false;
break;
}

// If the string does not match exactly, find which two entries
// it should be between.
if(i < allOptions.leng th-1){

// If we are not yet at the last listbox item, see if the
// search string comes between the current entry and the next
// one. If so, place the selection there.

lookAheadOption Text = allOptions(i+1) .text.toUpperCa se() ;
if( (toFind > nextOptionText) &&
(toFind < lookAheadOption Text) ){
oControl.select edIndex = i+1;
window.event.ca ncelBubble = true;
window.event.re turnValue = false;
break;
} // if
} // if

else{

// If we are at the end of the entries and the search string
// is still higher than the entries, select the last entry

if(toFind > nextOptionText) {
oControl.select edIndex = allOptions.leng th-1 // stick it
// at the end
window.event.ca ncelBubble = true;
window.event.re turnValue = false;
break;
} // if
} // else
} // for
} // function
Hope this helps...

Chris

Jul 22 '05 #4
CJM

"Raymond D'Anjou" <rd*****@savant softNOSPAM.net> wrote in message
news:%2******** *******@TK2MSFT NGP14.phx.gbl.. .
Looks nice CJM.
I had written something quick for a couple of my Combos but I'll take a
close look at your functions and may just integrate it in my pages.
Of course I'll give you full credit but no paycheck. :-)
Thanks for the code.


I'm afraid that I can't take the credit... it's a modified version of some
code found on the web, probably modified by a guy who also found it on the
web etc...

You'll probably find that Charles Babbage or Alan Turing wrote the first
version...!
Jul 22 '05 #5
A P
Hi CJM,

I have tried your code as is, I've just add values on the combo box. I
receive error message "Object Required" on the browser. Where does it
pertains to? I have paste the comple file:

<html>

<head>
<meta name="GENERATOR " content="Micros oft FrontPage 5.0">
<meta name="ProgId" content="FrontP age.Editor.Docu ment">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>DropDo wn Link</title>
<script src="/js/autocomplete.js "></script>
</head>

<body>
<p>
<form method="GET" name="frmlink">
<select size="1" name="selectlin k" onkeypress="lis tbox_onkeypress ();"
onblur="listbox _onblur();">
<option>Selec t a Program</option>
<option value='/c.asp'>Componen ts</option>
<option value='/me>ME</option>
</select>
</form>

</body>

</html>

Hope youmight help me.

Me

"CJM" <cj*******@news group.nospam> wrote in message
news:OB******** ******@TK2MSFTN GP10.phx.gbl...

"A P" <ap@textguru.ph > wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
Hi!

I have seen some techniques like this on the web. Currently, I'm using
Combo
box which values came from database table. One disadvantage is when the
combo box have lots of values, users are complaining since you cannot use keyboard to search the value that is needed. Hope you might help me.

regards,

Me
Use a <Select> tag as normal, but add a couple of event handlers in as
follows:

<select name="field1" onkeypress="lis tbox_onkeypress ();"
onblur="listbox _onblur();">
<option>1</option>
...
<option>n</option>
</select>

Then bang the following script in to a .js file and link it in... and hey
presto... you have autocomplete functionality.

// Auto-select listbox

// This script and the listbox on this page illustrates one
// way to create an "auto-complete" listbox, where the

var toFind = ""; // Variable that acts as keyboard buffer
var timeoutID = ""; // Process id for timer (used when stopping
// the timeout)
timeoutInterval = 250; // Milliseconds. Shorten to cause keyboard
// buffer to be cleared faster
var timeoutCtr = 0; // Initialization of timer count down
var timeoutCtrLimit = 3 ; // Number of times to allow timer to count
// down
var oControl = ""; // Maintains a global reference to the
// control that the user is working with.

function listbox_onkeypr ess(){

// This function is called when the user presses a key while focus is

in // the listbox. It maintains the keyboard buffer.
// Each time the user presses a key, the timer is restarted.
// First, stop the previous timer; this function will restart it.
window.clearInt erval(timeoutID )

// Which control raised the event? We'll need to know which control to
// set the selection in.
oControl = window.event.sr cElement;

var keycode = window.event.ke yCode;
if(keycode >= 32 ){
// What character did the user type?
var c = String.fromChar Code(keycode);
c = c.toUpperCase() ;
// Convert it to uppercase so that comparisons don't fail
toFind += c ; // Add to the keyboard buffer
find(); // Search the listbox
timeoutID = window.setInter val("idle()", timeoutInterval );
// Restart the timer
}
}

function listbox_onblur( ){
// This function is called when the user leaves the listbox.

window.clearInt erval(timeoutID );
resetToFind();
}

function idle(){
// This function is called if the timeout expires. If this is the
// third (by default) time that the idle function has been called,
// it stops the timer and clears the keyboard buffer

timeoutCtr += 1
if(timeoutCtr > timeoutCtrLimit ){
resetToFind();
timeoutCtr = 0;
window.clearInt erval(timeoutID );
}
}

function resetToFind(){
toFind = ""
}
function find(){
// Walk through the select list looking for a match

var allOptions = document.all.it em(oControl.id) ;

for (i=0; i < allOptions.leng th; i++){
// Gets the next item from the listbox
nextOptionText = allOptions(i).t ext.toUpperCase ();

// By default, the values in the listbox and as entered by the
// user are strings. This causes a string comparison to be made,
// which is not correct for numbers (1 < 11 < 2).
// The following lines coerce numbers into an (internal) number
// format so that the subsequent comparison is done as a
// number (1 < 2 < 11).

if(!isNaN(nextO ptionText) && !isNaN(toFind) ){
nextOptionText *= 1; // coerce into number
toFind *= 1;
}

// Does the next item match exactly what the user typed?
if(toFind == nextOptionText) {
// OK, we can stop at this option. Set focus here
oControl.select edIndex = i;
window.event.re turnValue = false;
break;
}

// If the string does not match exactly, find which two entries
// it should be between.
if(i < allOptions.leng th-1){

// If we are not yet at the last listbox item, see if the
// search string comes between the current entry and the next
// one. If so, place the selection there.

lookAheadOption Text = allOptions(i+1) .text.toUpperCa se() ;
if( (toFind > nextOptionText) &&
(toFind < lookAheadOption Text) ){
oControl.select edIndex = i+1;
window.event.ca ncelBubble = true;
window.event.re turnValue = false;
break;
} // if
} // if

else{

// If we are at the end of the entries and the search string
// is still higher than the entries, select the last entry

if(toFind > nextOptionText) {
oControl.select edIndex = allOptions.leng th-1 // stick it
// at the end
window.event.ca ncelBubble = true;
window.event.re turnValue = false;
break;
} // if
} // else
} // for
} // function
Hope this helps...

Chris

Jul 22 '05 #6
CJM

"A P" <ap@textguru.ph > wrote in message
news:Or******** ******@tk2msftn gp13.phx.gbl...
Hi CJM,

I have tried your code as is, I've just add values on the combo box. I
receive error message "Object Required" on the browser. Where does it
pertains to? I have paste the comple file:

<html>

<head>
<meta name="GENERATOR " content="Micros oft FrontPage 5.0">
<meta name="ProgId" content="FrontP age.Editor.Docu ment">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>DropDo wn Link</title>
<script src="/js/autocomplete.js "></script>
</head>

<body>
<p>
<form method="GET" name="frmlink">
<select size="1" name="selectlin k" onkeypress="lis tbox_onkeypress ();"
onblur="listbox _onblur();">
<option>Selec t a Program</option>
<option value='/c.asp'>Componen ts</option>
<option value='/me>ME</option>
</select>
</form>

</body>

</html>

Hope youmight help me.

Me


I'm not great at debugging Javascript, but what that error message probably
means is that when your event handler calls a routine, it cant find it.

It could be that the functions are are called something slightly different,
or more likely that it can't find your JS file (so check the path).

One thing you might want to try is include the Javascript in your main file
(as opposed to an extrernal JS file).

Chris
Jul 22 '05 #7

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

Similar topics

24
77383
by: London | last post by:
Hello Can you help me. By ASP How can I get the dropdown(control'name)'s selected value? What is it's property'name?
20
12432
by: Dannyboyo | last post by:
I have what I hope is a simple request. I can't really code in javascript, but I am pretty good at cusomizing it with slight modifications. I code in ASP and HTML. I am trying to capture customer input of product names to put on custom labels we make. Some of the labels will have our product names on them, but the customer can add other products that we do not sell. So, on my product detail page I want a textbox that can have rows copied...
0
2008
by: Mark | last post by:
Hi, I have a datalist that contains a textbox as well as a dropdown list. For each single row in the datalist the associated dropdown list can have at least one value What I would like to be able to do is when a single update button is clicked the textbox value along with the associated dropdown value is printed for each row in the datalist. The number of rows in the datalist can vary. Here is my Datalist code
5
10294
by: Gil | last post by:
Is there a way to tell if a combbox is in dropdown mode. I tried and if statement combobox.dropdown = true but i get an error. dropwndown function doesnt store if its true or false what i am trying to do is make an autoscroll combobox. like you have on html textbox's, but this time you hit enter for a change to be made. i do this because i dont want to requery every time a single letter is inputed. it would be too slow. so i make them hit...
2
4552
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was set to...it is set to false. Can someone show me what I am doing wrong and tell me the correct way? Thank you. In the page load event, I am doing the following:
2
2853
by: Peter | last post by:
ASP.NET 2003 In the DataGrid how do I select current cell value in the dropdown box when I click on the edit link, currently when I click on the edit link in the DataGrid the dropdown box appears in the cell, but allways the first item in the dropdown box is shown not the current cell value? How do I make the current value in the cell automaticaly be selected in the dropdown box.
0
1420
by: anjupt | last post by:
Hi, I can add values to a dropdown from 1 to 100 using a while loop in page load.ie Dim i = 1 While i <= 100 Me.DropDownList2.Items.Add(i) ' i = i + 1 End While this code if written in page load gives out a dropdown consisting of numbers 1 to 100 on execution of the page ..
0
993
by: staeri | last post by:
I want to replace a textbox with a dropdown in my FormView but I'm unsure of how to change the update parameters so that the value in the dropdown is saved. Right now I'm using: <UpdateParameters> <asp:Parameter Name="AccountGroup" Type="String" /> </UpdateParameters> This works when AccountGroup is in a textbox, but not in a dropdown.
11
7395
by: eureka | last post by:
Hi All, I'm training in Servlets, JSP and JavaScript, I have a web page in which there's a "StudentName" textbox and below it is a "Names" Dropdown list. Initially the Textbox is empty and the Dropdown doesnt have any items.. The requirement is that as soon as one goes on typing the letters in the StudentName-textbox the corresponding matching names have to appear
1
1855
by: Simone | last post by:
Hello, I am new to asp.net and I am in need of help. I have a dropdown that is attached to a SqlDataSource (DataSourceID). The dropdown has one column shown as text and another hidden as the value. However my SqlDataSouce returns 3 columns but I am only using two for the dropdown (value,text) but the third column I would like to place it in a textbox. So, SqlDataSource has (three columns "A, B, C") it populates a dropdown
0
8991
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...
1
9325
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
8244
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...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6076
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
4607
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
4876
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
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.