View Full Version : How to update an array from multiple select

06-05-2009, 03:28 PM

Im new to javascript / AJAX and would appreciate any help with this.

I have a multiple select box and want to be able to select from this box and transfer the selection accross to a div using an "Add" button. I have this working fine but I want to append to the list, rather than replace the list when further selections are made.

I somehow need the function to remember the original selected array and then merge the new selected array and the old array if another sleection is made. I have no idea how this would be done. Any ideas welcome. This is all I have so far...

function editOptions(action)
var optionsBox = document.getElementById('optionsBox');
var selectedArray = new Array();
var selObj = document.getElementById('productOptions');
var i;
var count = 0;
for (i=0; i<selObj.options.length; i++) {
if (selObj.options[i].selected) {
selectedArray[count] = selObj.options[i].value;

var strURL="ajax/selected_options.php?options="+newArray;


var req = getXMLHTTP();
if (req)
req.onreadystatechange = function()
if (req.readyState == 4)
// only if "OK"
if (req.status == 200)
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
req.open("GET", strURL, true);