Click here to Skip to main content
15,302,644 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

Count & Show number of selected items in listbox using javascript function.

UPDATE [SM]:
Whatever question OP had was resolved by herself. Posted as an answer.
Posted
Updated 19-Apr-11 5:39am
v3
Comments
Sandeep Mewara 19-Apr-11 5:04am
   
Not clear.

1 solution

Javascript:

C#
function selectall(cb_selall)
     {
     if (cb_selall.checked)
       {

         for(i=0; i<document.form1.li_mana_cards.options.length; i++)
            {
               document.form1.li_mana_cards.options[i].selected = true;
            }
            }
     else
     {

     for(i=0; i<document.form1.li_mana_cards.options.length; i++)
            {
               document.form1.li_mana_cards.options[i].selected = false;
            }

      }
      var s=document.getElementById('li_mana_cards');
      CountItems(s);
       }

      function CountItems(lb) {
            var count = 0;
            var lbl=document.getElementById('lbl_selected');
            for (var i = 0; i < lb.options.length; i++)
             {
                if (lb.options[i].selected) {
                    count++;
              }
            }
           document.getElementById('lbl_selected').innerHTML=count;
         }


Page Load:

MIDL
cb_red_inac.Attributes.Add("onclick", "javascript:selectall(this);")
           li_mana_cards.Attributes.Add("onchange", "javascript:CountItems(this);")
   

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