In my application I have the auto complete like textbox option with Listbox. If I type a word in the text box it should select appropriate list item in the list box. And also if select a list box item, the selected value to be reflected in the text box.
Here everything is working fine except that if I key on the some filter character, the typed characters are repeating twise in the textbox.
And Keyboard navigation is not working for Up/Down arrow keys after the user keyed in the textbox.
<body> <form id="form1" runat="server"> <telerik:RadScriptManager ID="RadScriptManager1" runat="server"> </telerik:RadScriptManager> <div> Search: <telerik:RadTextBox ID="RadTextBox1" ClientEvents-OnKeyPress="filterListBox" SelectionOnFocus="SelectAll"runat="server"> </telerik:RadTextBox> <telerik:RadListBox ID="RadListBox1" runat="server" Sort="Ascending"
OnClientSelectedIndexChanged
="GetProgramName" >
<Items> <telerik:RadListBoxItem Text="Kansas" Value="KS" /> <telerik:RadListBoxItem Text="Kentucky" Value="KY" /> <telerik:RadListBoxItem Text="Texas" Value="TX" /> <telerik:RadListBoxItem Text="Missouri" Value="MO" /> <telerik:RadListBoxItem Text="Nebraska" Value="NE" /> <telerik:RadListBoxItem Text="Neubraska" Value="N1E" /> <telerik:RadListBoxItem Text="New Mexico" Value="NM" /> <telerik:RadListBoxItem Text="Oklahoma" Value="OK" /> <telerik:RadListBoxItem Text="Arizona" Value="AZ" /> <telerik:RadListBoxItem Text="South Dakota" Value="SD" /> <telerik:RadListBoxItem Text="Colorado" Value="CO" /> <telerik:RadListBoxItem Text="Iowa" Value="IA" /> <telerik:RadListBoxItem Text="Illinois" Value="IL" /> </Items> </telerik:RadListBox> </div> <script type="text/javascript">
function
filterListBox(sender, e) {
var list = $find("ctl00_Content_lstSelectPgm");
var searchText = sender.get_value() + e.get_keyCharacter();
var items = list.get_items();
for (var i = 0; i < items.get_count(); i++) {
var item = items.getItem(i);
var SelectPrgm;
if (item.get_text().toLowerCase().startsWith(searchText.toLowerCase())) {
item.select();
item.ensureVisible();
item.scrollIntoView;
SelectPrgm = $find(
"ctl00_Content_txtSelectPgm")
SelectPrgm.set_value();
SelectPrgm.set_value(searchText);
break;
}
}
}
function
GetProgramName(sender, args) {
var SelectPrgm;
SelectPrgm = $find(
"ctl00_Content_txtSelectPgm")
SelectPrgm.set_value(
'');
SelectPrgm.set_value(sender.get_selectedItem().get_value())
document.getElementById(
"ctl00_Content_cmdOk").disabled = false;
document.getElementById(
"ctl00_Content_txtSelectPgm")
}
</script> </form> </body>