Unable to store values of dropdown in an array
<p>In my application I have a link that when clicked adds another html select into a div via a javascript function. Listed below is the code (drugCount is a count of how many items have been added)</p>

<pre><code>var drugCount = 0;
function addDrug() {

    var oldInner = document.getElementById('drugDiv').innerHTML;
    document.getElementById('drugDiv').innerHTML = oldInner + '&lt;table id="drug' + drugCount + '" class="detailTable"&gt;&lt;tr&gt;&lt;td&gt;Drug Type (Drug ' + drugCount + ')&lt;/td&gt;&lt;td&gt;&lt;select id="drugType' + drugCount + '" onchange="changeDrug(' + drugCount  + '); return false;"&gt;&lt;option value="' + drugCount + '"&gt;' + drugCount + '&lt;/option&gt;&lt;option value ="' + drugCount + '"&gt;' + drugCount + '&lt;/option&gt;&lt;/select&gt;&lt;td&gt;Drug (Drug ' + drugCount + ')&lt;/td&gt;&lt;td&gt;&lt;select id="drug' + drugCount + '"&gt;&lt;option value="' + drugCount + '"&gt;' + drugCount + '&lt;/option&gt;&lt;option value ="' + drugCount + '"&gt;' + drugCount + '&lt;/option&gt;&lt;/select&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;';
    document.getElementById('drugDiv').style.display = 'inherit';
    document.getElementById('drugType' + drugCount).innerHTML = document.getElementById('ddlDrugType').innerHTML;
    drugCount = drugCount + 1;
}
</code></pre>

<p>The problem I am having, is if the link to add another group of selects is hit, it automatically makes the selected value of the previous selects added this way reset to option one. I want to keep these the same as they were when another item is added so i figured i could store all the values into an array, then after the new item is added, just re select the right selected value from the array. I am unable to get this to work. Listed below is my attempt to create an array to hold the values. Does anyone see what is wrong? The function will not even run when the below code is put into the start of the function (this code is the start of the function posted above)</p>

<pre><code>    var drugSelection = new Array();
    var drugtemp;
    if (drugCount &gt; 0) {
        for (var i = 0; i &lt;= drugCount; i++) {
            drugtemp = document.getElementById('drugType' + i);
            drugSelection[i] = drugtemp.options[drugtemp.selectedIndex].value;
        }
    }
</code></pre>

<p>Thank you for your help.</p>
