[solution] Prototype Javascript: Select Multiple Dropdown Items (values)


min read

My profile

Share this:

So I needed to have all values from:
[code:1:8f00df4175] select multiple=”multiple” name=”cats” id=”cats” size=”5″>
option value=”73″>Catg Naam</option>
option value=”70″>CatNaam1</option>
option value=”90″>CatNaam2</option>
option value=”80″ >CatNaam3</option>

how to do this? ( in order to make it usable for AJAX requests ).
A solution is to serialize them to XML but I needed a string.

Recoded from:

Here’s how to get 73+70+80 if 3 options are selected:

* Recoded by Ramon Fincken (www.ramonfincken.com) from: http://ehsan.bdwebwork.com/2006/12/20/javascript-select-multiple-dropdown-items/
function getmultiplevalues(input)
var opt = input;

var numofoptions = opt.length;
var selValue = new Array;

var j = 0;
for (i=0; i<numofoptions; i++)
if (opt[i].selected === true)
selValue[j] = opt[i].value;

selValue = selValue.join(“+”)

return selValue;

Share this:

Leave a Reply

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