Mayur  Gujrathi

Mayur Gujrathi

  • 377
  • 4.1k
  • 1m

How to select multiple/all items in listbox

Aug 23 2011 5:15 AM

I have a list box like this
 <select id="ddlBranch" name="ddlBranch" multiple runat="server" style="width:100%;">
 </select>
in this listbox there are no of items

on blur of textbox i am fetching some values from database
I need whatever  items i am retrieving  matching with listbox should be all  selected in list box
 


with the help of following script i am getting able to selected only one value from listbox
function getSelet()
           {
                 if (document.getElementById('hidBranchLst').value != '') {
                var strBranch = document.getElementById('hidBranchLst').value
                var strBranchList = strBranch.split('|');
                var MulSel = document.getElementById('ddlBranch');
                MulSel.multiple = true;
                for (var j = 0; j < strBranchList.length; j++) {
                    alert(strBranchList[j].toString());
                    for (var i = MulSel.options.length - 1; i >= 0; i--) {
                        if (MulSel.options[i].value == strBranchList[j].toString()) {
                            MulSel.selectedIndex = i;
                        }
                    }
                }
            }
        }

Answers (1)