Auto Complete Drop Down Problem

J

jediknight

Hi
I have some javascript which allows me to have some sort of
autocomplete functionality for drop downs but I cannot get the
selectedIndex event to fire when the user selects the item from the
drop down. Typically I want the user to be able to select from a drop
down by typing and then autocompleting depending on what he types.
Then I need the selectedIndex changed event to fire so that I can do
some run serverside code.


C# as follows:

myDDL.Attributes.Add("onkeydown", "checkKey(this, event);return
false;");


javascript as follows:

var searchID;
var searchValue;

function checkKey(oList, e) {
// Re-initialize if the
if(oList.id != searchID) {
searchID = oList.id;
searchValue = "";
}

var theKey;
var binIE;
// check for browser event model
if(window.event) { theKey = window.event.keyCode; binIE = true; }
else { theKey = e.which; binIE = false; }
logThis("new keycode = " + theKey);
if(theKey == 8) { // check for backspace
searchValue = ""; // clear the filter
}
// check for alphanumeric keys and append to the search value
else if((theKey >= 48 && theKey <= 57) || (theKey >= 65 && theKey
<= 90) ||
(theKey == 32) || (theKey >= 96 && theKey <= 105)) {
searchValue += String.fromCharCode(theKey).toLowerCase();
}
else { return false; }
// loop through the list to select the proper item
if(searchValue != "") {
for(var iCheck=0;iCheck<oList.options.length;iCheck++) {

if(oList.options[iCheck].text.toLowerCase().indexOf(searchValue) == 0)
{
oList.options[iCheck].selected = true;
return;
}
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,228
Latest member
MikeMichal

Latest Threads

Top