Jump to content
Xtreme .Net Talk

Trying to use .js file for dropdownlist autocomplete in ASP.NET application


Recommended Posts

Posted

When I run the page, I get an "Object Expected" on line 16, which points to the asp:dropdownlist line in the HTML of the .aspx page.

 

Here's the .js file:

 

var keys;

var timeStamp;

timeStamp = new Date();

function dd_onkeypress(DropDownList1) {

* var key = event.keyCode;

* event.returnValue=false;

*//a-z, A-Z, 0-9

* if ((key>=97 && key<=122) || (key>=65 && key<=90) || (key>=48 && key<=57)) {

* ********key = String.fromCharCode(key);

* ********var now = new Date();

* ********var diff = (now.getTime() - timeStamp.getTime());

* ********timeStamp = new Date();

* ********//1 seconds = 1000 milliseconds<BR>***

* ********if (diff > 1000) {

* ********************keys = key;****

* *********************} else {

* *********************keys = keys + key;

* *********************}

* *********************var cnt;

* *********************//for (cnt=0;cnt<document.all(DropDownList1).children.length;cnt++)

* *********************//for (cnt=0;cnt<DropDownList1.children.length;cnt++)

* *********************for (cnt=0;cnt<DropDownList1.options.length;cnt++) {

********************** var itm = DropDownList1.options[cnt].text;

********************** if

(itm.substring(0,keys.length).toLowerCase()==keys.toLowerCase())

* *********************{

* *********************//var itm = document.all(DropDownList1).children[cnt].text;

* *********************//var itm = DropDownList1.children[cnt].text;

* *********************//if (itm.substring(0,keys.length).toLowerCase()==keys.toLowerCase())

{

//document.getElementById(DropDownList1).selectedIndex = cnt;

DropDownList1.selectedIndex = cnt;

break;

}

}

}

//document.all(DropDownList1).onchange();

}

 

For the Page_Load in the .aspx.vb file I've got:

DropDownList1.Attributes.Add("onkeyup", "javascript:return dd_onkeypress('DropDownList1');")

Posted
Is this a javscript or asp.net error? Have you made sure your dropdown is declared?

 

Well, if I comment out the Page_Load .aspx code that calls the .js file's function, then the page doesn't throw an error, and the dropdownlist acts as it should from the .NET toolbox

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...