Trouble populating Input name arrays with javascript

They have: 13 posts

Joined: Mar 2005

Hey, I'm trying to populate a series of drop down boxes that contain text and numerical indicies as option values from a database. I'm using php to populate the select boxes with the different options and then javascript to set the selectedIndex to correspond with input that the user has previously submitted to the form.

The function I am using to find out what the selected index of the value in question is:

function getOptionIndex(theElement) {

    var select = theElement;  //get a reference to the select object

    for (var i = 0; i < select.options.length; i ++) {

      if (select.options[i].value == yy)

        return i;

    }

    return -1;

  }
'

The different select box name parameters, which repeat themselves, are labeled with the name "activity[]." So to get each of these elements to show what was previously selected I use the format: document.form.elements[activity[]][i], inside a php loop. This is working fine for me expect when i try to access the element document.form.elements[activity[]][0], which doesn't do anything or give me any errors for that matter.

Is there anything I am doing wrong? or any suggestions to make this work better?

Thanks in advance,
Andy