How to dynamically insert a table row with a select box with options in a table using javascript?
<p>I am having a hard time in inserting table rows dynamically since I haven't really tried it before. What I'm supposed to do is to insert a new table row with a select box with options from the an arraylist.</p>

<p>So far, this is my code:</p>

<p>HTML</p>

<pre><code>&lt;TABLE id="dataTable"&gt;         
    &lt;TR&gt;             

        &lt;TD&gt; 1&lt;/TD&gt;             
        &lt;TD&gt; 
            &lt;select name="option"&gt;
            &lt;%for(int i = 0; i &lt; jList.size(); i ++){%&gt;
            &lt;option value="&lt;%=jList.get(i).getName%&gt;"&gt;&lt;%=jList.get(i).getName%&gt;&lt;/option&gt;
            &lt;%}%&gt;
            &lt;/select&gt;
        &lt;/TD&gt;         
    &lt;/TR&gt;     
    &lt;/TABLE&gt; 
&lt;INPUT type="button" value="Add Row" onclick="addRow('dataTable')" /&gt;  
</code></pre>

<p>JAVASCRIPT</p>

<pre><code>function addRow(tableID) {               
    var table = document.getElementById(tableID);               
    var rowCount = table.rows.length;         
    var count = rowCount + 1;
    var row = table.insertRow(rowCount);               
         //*** EDIT ***               
    var cell1 = row.insertCell(0);             
    cell1.innerHTML = count;
    var cell2 = row.insertCell(1);             
    var element2 = document.createElement("select");   
//how do i put the options from the arraylist here?
    cell2.appendChild(element2);  



}
</code></pre>

<p>also, I would also like to know how to pass a variable from the javascript function to a java servlet because every time I pass the variable count in a hidden input type, the input does not contain the count. I hope you can help me with my dilemma.                                                     </p>