Count Items Selected in List

[Total: 0    Average: 0/5]

This will count the number of items selected in a form select list.

Body Code:

<script>
function doIt()
{
  var _x=0;
  var _F=document.exf1.s1.options;
  for(var i=0;i<_F.length;i++)
  {
    _x+=(_F[i].selected)?1:0;
  }
  alert(_x);
}
</script>
<form name=exf1>
<select name=s1 size=5 multiple>
    <option value=0>Zero</option>
    <option value=1>One</option>
    <option value=2>Two</option>
    <option value=3>Three</option>
    <option value=4>Four</option>
    <option value=5>Five</option>
    <option value=6>Six</option>
    <option value=7>Seven</option>
    <option value=8>Eight</option>
    <option value=9>Nine</option>
</select>
<input type=button name=b1 value="Count Them" onclick=doIt()>
</form>

Times Viewed: 2

Leave a Reply

Your email address will not be published. Required fields are marked *