Javascript: how to "implode" a select

Thought I’d post this, as I’m sure some will find it handy.

If you’re trying to get ALL the SELECTED values of a listbox or dialog list over the web via javascript, you can use the following:

function implodeSelect(object){

var s

s=“”

for (var i=object.options.length-1; i >= 0;i–) {

if (object.options[i].selected){

s=s+((s=="")?"":'~')+object.options[i].text;

}

}

if (s==“”) {s=“empty”}

return s

}

Say you’ve got a listbox with possible values of Red, Blue, or Green, and the user’s selected Red and Green. This function will yield “Red~Green”.

Enjoy!