zubie Posted October 8, 2003 Posted October 8, 2003 Hi all I have a dropdownlist that can have upto 400 or so items in it. I wish to use something list autocomplete to search through this list. i.e. Type 'a' and get the first A in the list, type 'ae' and get the first 'ae' in the list I know this is not possible without using Java script. Does anyone out there have an example of this script and how to use it. thanks ZuBiE Quote
WebJumper Posted October 8, 2003 Posted October 8, 2003 Hi zubie, i have written it for you: <script language="javascript"> var str = ""; var timerID = null; function jsKeyPress() { if (timerID != null){ window.clearTimeout(timerID);} //delete old timer if (window.event.keyCode == 27){ //Esc pressed window.clearTimeout(timerID); str = ""; return false;} str += String.fromCharCode(window.event.keyCode); for(i=0; i<document.forms[0].ddlStelle.options.length; i++) { if (document.forms[0].ddlStelle.options[i].text.toLowerCase().indexOf(str) == 0) { document.forms[0].ddlStelle.selectedIndex = i; break; } } timerID = window.setTimeout("str='';", 500); return false; } </script> <asp:DropDownList onkeypress="return jsKeyPress();" id="ddlStelle" runat="server"></asp:DropDownList></td> Regards, Stefan Quote
zubie Posted October 8, 2003 Author Posted October 8, 2003 Hi I get the error "Could not find any attribute 'onkeypress' of element dropdowlist" any ideas? cheers ZuBiE Quote
WebJumper Posted October 8, 2003 Posted October 8, 2003 Are you using ASP.net DropDownList or the normal HTML-Control? Do you create the DropDownList synamic from code-behind or the placed it in the designer to your ASP.net Site? Paste your code here, i will have a look... Quote
zubie Posted October 9, 2003 Author Posted October 9, 2003 I'm creating the DDL by dropping it on the screen then populating it from Code behind. What part of the code do you want me to paste? Quote
zubie Posted October 9, 2003 Author Posted October 9, 2003 OK I seem to have the Javascript working for the onkeypress but I now recieve Microsoft JScript runtime error: 'document.forms.0.ddlCustomer.options' is null or not an object from the line for(i=0; i<document.forms[0].ddlCustomer.options.length; i++) thanks in advance for the help ZuBiE Quote
Rea Posted January 26, 2006 Posted January 26, 2006 (edited) Not work :confused: Not work :confused: nothing happens ...??? ContactSearch.ascx <script language="javascript"> var str = ""; var timerID = null; function jsKeyPress() { if (timerID != null){ window.clearTimeout(timerID);} //delete old timer if (window.event.keyCode == 27){ //Esc pressed window.clearTimeout(timerID); str = ""; return false;} str += String.fromCharCode(window.event.keyCode); for(i=0; i<document.forms[0].name.options.length; i++) { if (document.forms[0].name.options.text.toLowerCase().indexOf(str) == 0) { document.forms[0].name.selectedIndex = i; break; } } timerID = window.setTimeout("str='';", 500); return false; } </script> <asp:dropdownlist id="name" runat="server" AutoPostBack="True" Width="300px" onkeypress="return jsKeyPress();"></asp:dropdownlist> Edited January 26, 2006 by Rea Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.