简体   繁体   中英

why listbox selected index changed is not firing?

I have written a javascript method to sortlistbox items and it works well in a sense that the item that I type in text box gets highlighted.

But when I click on the highlighted item it dosen't gets selected. Why?
The selectedIndexchanged is not working.

Here is my javascript code:

 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;
     }

Do this, then call your function inside, you need to reference jquery library :

 $(document).ready(function() {    
            $('#' + '<%= DropdownName.ClientID %>').change(function() {
                      // Call function here...
               });

            });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM