Counting Selected Entries in a Drop Down List

Question: How do you show how many items have been selected from a multiple select drop-down? I.E.. I would like to say "select ten names" and show a number next to the list 0, then 1, 2, 3, for each selection, up to 10?How do you show how many items have been selected from a multiple select drop-down? I.E.. I would like to say "select ten names" and show a number next to the list 0, then 1, 2, 3, for each selection, up to 10?
Ralph

Answer: The list is considered all one field so there is no way to insert processing as each entry is selected or unselected. You will have to wait until the person filling the form out moves on to the next field before being able to check how many entries they selected.

Here is an example select list that allows multiple entries to be selected. When you move off of the field an alert will display the count of the number of entries selected for you.

This form uses onblur="valList(this);" on the select tag to call the validation for the list that checks how many entries in the list have been selected. The actual code for the function that does the count is as follows:

function valList(thissel) {
var selCount = 0;
for (var i=0; i<thissel.length; i++) {
  if (thissel[i].selected) {
    selCount += 1;
    }
  }
alert(selCount);
}

 

This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow
Donate