By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,654 Members | 1,580 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,654 IT Pros & Developers. It's quick & easy.

Ho to make listbox expandable using javascript?

P: 2
Hi,

Code Explanation:

I have one text box for name,and one dropdown when I enter 'bo' then dropdown filled from database.Values in listbox are 1)bob 2)bobby 3)Bony etc exists in db. Now my requirement is given below.

I want the name listbox field expand automatically to show all my matches to what has been entered in the name textbox field. e.g. If I am entering just ‘bo’ in the name field actually 3 names are there but only the first is shown unless the user actually clicks the drop-down, so they sometimes assume that that is the only name that matches and don’t bother clicking to see if there are others.

Hot to make list box expandable in above java script code.?

Pls. advice me asap

Thanks & RegaRDS
VIBS

Please check this code.

Expand|Select|Wrap|Line Numbers
  1. <%@ LANGUAGE="VBSCRIPT" %>
  2. <%
  3. Response.AddHeader "Pragma", "no-cache"
  4. Response.AddHeader "cache-control", "must-revalidate, private, no-cache"
  5. Response.Expires = -1500
  6. %>
  7. <%
  8. Response.Expires = 0
  9. On Error Resume Next
  10. Set DataConnPhoneBk = Server.CreateObject("ADODB.Connection")
  11. DataConnPhoneBk.ConnectionTimeout = Session("DataConnPhoneBk_ConnectionTimeout")
  12. DataConnPhoneBk.CommandTimeout = Session("DataConnPhoneBk_CommandTimeout")
  13.  
  14. 'Next line added as ICL had forgot to setup the connection string to the database.
  15.  
  16. DataConnPhoneBk.Open ("Driver={SQL Server};Server=localhost;Database=WAR;")
  17.  
  18. Set cmdTemp = Server.CreateObject("ADODB.Command")
  19. Set MapListResults = Server.CreateObject("ADODB.Recordset")
  20. cmdTemp.CommandText = "SELECT Login_id, User_Name FROM User ORDER BY User_Name"
  21. cmdTemp.CommandType = 1
  22. Set cmdTemp.ActiveConnection = DataConnPhoneBk
  23. MapListResults.Open cmdTemp, , 0, 1
  24. %>
  25.  
  26. <%
  27. If MapListResults.EOF then
  28. itsgonewrong = 0
  29. else
  30. itsgonewrong = 1
  31. end if
  32.  
  33. %>
  34. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  35. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  36. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  37. <head>
  38. <title>United Utilities - Tools - Maps and Addresses</title>
  39. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  40. <link rel="stylesheet" href="/styles/kcmain.css" type="text/css" />
  41.  
  42. <script type="text/javascript" language="JavaScript">
  43. debugger;
  44.  
  45. var sites;
  46. sites = new Array(<%
  47. while Not MapListResults.EOF
  48. Response.Write(Chr(34) & Trim(MapListResults("User_Name")) & "|" & Trim(MapListResults("Login_id")) & Chr(34))
  49. MapListResults.MoveNext
  50. if Not MapListResults.EOF then Response.Write(",") end if
  51. wend
  52.  
  53. %>);
  54.  
  55. function filterSite(evt)
  56. {
  57. // empty the ddm
  58. document.SearchMapForm.mapsmenu.options.length = 0;
  59.  
  60. // grab the filter text
  61. txtFilter = document.SearchMapForm.filterTxt.value;
  62.  
  63. // loop through the array of sites to repopulate
  64. for(i=0;i<sites.length;i++)>
  65. {
  66. if( sites[i].substring(0,txtFilter.length).toUpperCase() == txtFilter.toUpperCase() )
  67. {
  68. site_ids = sites[i].split("|");
  69. document.SearchMapForm.mapsmenu.options.length = document.SearchMapForm.mapsmenu.options.length + 1;
  70. document.SearchMapForm.mapsmenu.options[document.SearchMapForm.mapsmenu.options.length-1].value = site_ids[1];
  71. document.SearchMapForm.mapsmenu.options[document.SearchMapForm.mapsmenu.options.length-1].text = site_ids[0];
  72. }
  73. }
  74. }
  75. </script>
  76.  
  77. </head>
  78. <body önLoad="filterSite(event)">
  79.  
  80. <% 'side menu %>
  81. <form name="SearchMapForm" id="form1" method="post" action="vibs.asp">
  82. <input name="filterTxt" type="text" id="filterTxt" önKeyUp="filterSite(event)" size="40">
  83. <select name="mapsmenu" size=5>
  84. <%
  85. MapListResults.ReQuery()
  86. while not MapListResults.EOF
  87. %>
  88.  
  89. <option value="<%=MapListResults("login_id")%>"><%=MapListResults("User_Name")%></option>
  90. <%
  91. MapListResults.MoveNext
  92. wend
  93. %>
  94. </select>
  95.  
  96. </form>
  97.  
  98. </body>
  99. </html>
Oct 12 '11 #1
Share this Question
Share on Google+
1 Reply


Dormilich
Expert Mod 5K+
P: 8,639
a) it’s onload not önLoad
b) the length property of an array/list is read-only
c) new option elements are created either via DOM (document.createElement()) or new Option()
Oct 12 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.