I have a listbox filled with employee names. On the same page I have a textbox that I can type letters in and as I type the name that matches will be highlighted. My problem is that if the highlight moves below the bottom of the listbox the list does not scroll. How can I get this to scroll?
Here is my code:
ASPX page:
javascript:Code:<table> <tr> <td><asp:Label ID="Label1" runat="server" Text="Search" Font-Bold="True" ForeColor="#999999" /></td> <td><asp:TextBox ID="txtSearch" runat="server" onkeyup="return SearchList();" xmlns:asp="#unknown" /></td> </tr> </table> </div> <div align="center" class="datacellgreen"> <asp:Label ID="Label2" runat="server" Text="Highlight the employees you wish to add in the list below:" Font-Bold="True" ForeColor="#999999" Width="100%"></asp:Label> </div> <div align="center"> <asp:ListBox ID="lstEmpList" runat="server" Height="292px" SelectionMode="Multiple" Width="100%"></asp:ListBox> </div>
Thanks.Code:function SearchList() { //var l = ; var tb = document.getElementById('<%= txtSearch.ClientID %>'); for (var i = 0; i < document.getElementById("lstEmpList").options.length; i++) { //alert("i: " + i + ", list: " + document.getElementById("lstEmpList")[i].text.toLowerCase() + ", TB: " + tb.value.toLowerCase()); if (document.getElementById("lstEmpList")[i].text.toLowerCase().match(tb.value.toLowerCase())) { document.getElementById("lstEmpList").options[i].selected = true; return false; } else { ClearSelection(); } } } /********************************************************************/ function ClearSelection() { document.getElementById("lstEmpList").selectedIndex = -1; }


Reply With Quote
Bookmarks