Multiple select problem (JS)

Jack Michaelson's picture

He has: 1,733 posts

Joined: Dec 1999

I'm trying to display the number of selected items in a multiple select. For instance, when a user selects option D, F and H, I would like to get the number 3 somewhere, somehow...

Anyone got a clue?
Thanx in advance Smiling

Shakespeare: onclick || !(onclick)

Jack Michaelson's picture

He has: 1,733 posts

Joined: Dec 1999

Nevermind, after a short break I came up with it in no time:

SelectedArray = new Array(0);
for (var i=0; i < document.amForm.OisSelect.options.length; i++)
{
if(document.amForm.OisSelect.options[i].selected)
{
//alert(document.amForm.OisSelect.options[i].value);
SelectedArray.length = SelectedArray.length+1;
SelectedArray[SelectedArray.length-1] = document.amForm.OisSelect.options[i];
}

}
alert(SelectedArray.length);
}
'
[edit]typo[/edit]

Shakespeare: onclick || !(onclick)

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.