| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| bubberz 
 
 
 Joined: 24 Aug 2005
 Posts: 4
 
 
 | 
			
				|  Posted: Wed Aug 24, 2005 10:43 am    Post subject: Trying to use .js file for dropdownlist autocomplete |   |  
				| 
 |  
				| I'm trying to use a .js file to get autocomplete on a dropdownlist control in my ASP.NET application, but keep getting a syntax error. 
 The error on the .js file is:
 
 Line 15, Char 1, Object Expected:
 
 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++) {
 var itm = document.all(DropDownList1).children[cnt].text;
 if (itm.substring(0,keys.length).toLowerCase()==keys.toLowerCase())
 {
 document.getElementById(DropDownList1).selectedIndex = cnt;
 break;
 }
 }
 }
 //document.all(DropDownList1).onchange();
 }
 
 In my Page_Load .aspx page, I've got:
 DropDownList1.Attributes.Add("onkeyup", "javascript:return dd_onkeypress(this);")
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| administrator Site Admin
 
 
 Joined: 01 Oct 2004
 Posts: 183
 
 
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| bubberz 
 
 
 Joined: 24 Aug 2005
 Posts: 4
 
 
 | 
			
				|  Posted: Thu Aug 25, 2005 12:29 pm    Post subject: |   |  
				| 
 |  
				| Line 15 is: 
 keys = keys + key;
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| bubberz 
 
 
 Joined: 24 Aug 2005
 Posts: 4
 
 
 | 
			
				|  Posted: Thu Aug 25, 2005 4:18 pm    Post subject: |   |  
				| 
 |  
				| Sorry, the "Object Expected" is pointing to the HTML line of the .aspx page for the asp:dropdownlist tag, and not the .js file |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| administrator Site Admin
 
 
 Joined: 01 Oct 2004
 Posts: 183
 
 
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| bubberz 
 
 
 Joined: 24 Aug 2005
 Posts: 4
 
 
 | 
			
				|  Posted: Fri Aug 26, 2005 9:34 am    Post subject: |   |  
				| 
 |  
				| Thanks so much for helping! 
 The code behind is:
 
 DropDownList1.Attributes.Add("onkeypress", "javascript:dd_onkeypress(this);return false;")
 
 Line 15 is the HTML of: <asp:dropdownlist
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| administrator Site Admin
 
 
 Joined: 01 Oct 2004
 Posts: 183
 
 
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		|  |