Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have written a javascript method to sortlistbox items it works well in a sence that the item that i type in text box gets highlited but when i click on the highlighted item it dosent gets selected why? the selected indexchanged is not working. here is my javascript code:

C#
function SearchList() {
         var l = document.getElementById("<%= LBox.ClientID %>");
         var tb = document.getElementById("<%= txtDepartments.ClientID %>");
         if (tb.value == "") {
             ClearSelection(l);
         }
         else {
             for (var i = 0; i < l.options.length; i++) {
                 if (l.options[i].value.toLowerCase().match(tb.value.toLowerCase())) {
                     l.options[i].selected = true;

                     return false;
                 }
                 else {
                     ClearSelection(l);
                 }
             }
         }
     }

     function ClearSelection(l) {
         l.selectedIndex = -1;
     }
Posted
Comments
Rockstar_ 18-Nov-13 4:58am    
Server side or client side checking?
If server side make autopostback true...!

Make auto post back to True..................
 
Share this answer
 
Once it's highlighted, it is selected. clicking on a selected item does not change the index, so does not fire the selectedIndexChanged event.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900