I am trying to populate a multiple select box using javascript, but am
having problems with the name. When I change the name to “codes[]” I
can’t get the javascript to find the form element, but without the [] on
the end, rails wont read all of the selected values.
Here is an example of the javascript working, but when you submit the
array is not passed across for the codes. Anyone work with this sort
of thing before?
Must be the 5 minute rule, after I posted this I figured it out.
function setOptions(chosen) {
var formObj = document.addCodes;
var selectBox = formObj.elements[‘codes[]’]
selectBox.options.length = 0;
var len = data[chosen].length;
for(i=0; i<len; i++) {
selectBox.options[selectBox.options.length] =
new Option(data[chosen][i], data[chosen][i]);
}
}