I have a select box that I am getting multiple values from and storing them in an Arrayusing JQuery.
I would like to know how I can then use the contents of this Array to populate options in another select box.
So currently I've got this:
$('#addBtn').click(function(e){
e.preventDefault();
//Get the selected Items in the dropdown 1
var selected = new Array();
$('#compresult option:selected').each(function(){
selected.push($(this).val() + " " + $(this).text());//Add to Array
});
//Update contents of dropdown 2 with the Array
});
My HTML for dropdown is :
<select multiple="multiple" name="contributors[]" id="compresult">
<option value="0"></option>
<option value="3610">X</option>
<option value="3605">Y</option>
<option value="335">Z</option>
</select>
If I select option X and Y my selected array in my JS Code outputs this:
Array [ "3610 X", "3605 Y" ]
How can I then use these values to populate another dropdown? i'm trying to implement an ADD/REMOVE from list functionality type thing.
EDIT: EXPECTED OUTPUT OF DROPDOWN 2
<select multiple="multiple" name="dropdown2" id="compresult">
<option value="3610">X</option>
<option value="3605">Y</option>
</select>