Checkboxes created with dynamic rows wont work as expected
<p>I have a dynamic table where everytime I click on 'add' button a new row will be added.Each row contains one checkbox. I am trying to insert the values of checkboxes as 'on' or 'off' in the database. I have used the following technique to detect the checked and unchecked checkboxes.</p>

<pre><code>var cell1 = document.createElement("TD");
var element1 = document.createElement("input");
element1.type = "checkbox";
element1.checked="checked";
element1.name="active";
element1.value="on";
element1.onclick =function checkme(){
    if (document.getElementById('tbodyId').rows[rowCount-1].cells[0].getElementByName("active").firstChild.value==true) {
        document.getElementById('tbodyId').rows[rowCount-1].cells[0].getElementByName("active").firstChild.value='on'; 
        } 
   else { 
       document.getElementById('tbodyId').rows[rowCount-1].cells[0].getElementById("active1").firstChild.value = 'off';
       document.getElementById('tbodyId').rows[rowCount-1].cells[0].getElementById("active1").firstChild.checked = true;   
   }
};
cell1.appendChild(element1);
var element0 = document.createElement("input");
element0.type = "hidden";
element0.id="active1";
element0.name="active";
element0.value="off";
element0.style="display: none;" ;
cell1.appendChild(element0);
row.appendChild(cell1);
</code></pre>

<p>It works fine with the first two checkboxes in the first two dynamic rows.but from the the third box it returns 'off' for 'on' and 'on' for 'off'. Can anyone let me know what is the problem? Thanks in advance</p>
