Javascript - multiple select selectboxes

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?

<select name="Division" size="1"


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]);

On Tuesday 08 August 2006 19:36, Bob wrote:

Must be the 5 minute rule, after I posted this I figured it out.

I’ve got a few functions of this kind in my ProtoPlus library. If you’re
interested, have a look at


Michael S.
mailto:[email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs