Checkbox values to array -- even when not checked

R

Rich_C

Javascript is my weakness, so I'm grasping for any help here.

I have a form that allows users to dynamically add rows. One of the
cells contains a checkbox. When the form is submitted, I create an
array of checkbox values, so I need a value for each checkbox, even if
it was not checked.

I currently have an OnClick event on the checkbox that updates a hidden
field with 0 or 1 depending on whether the checkbox is checked or not.
This works, but only if there is a single row in the form. I assume
this is because the hidden field in the cloned row has the same name as
the other hidden field(s) and thus js doesn't know which one to update.

Can anyone help me with a solution to this?

The row gets cloned here, so I'd like to incorporate any solution into
this script if possible:

function insert(btn) {var cell, newRow, row, sect;
if((cell = btn.parentNode) && (row = cell.parentNode) &&
row.cloneNode && (sect = row.parentNode) && sect.insertBefore)
{
newRow = row.cloneNode(true);
/* If you need to alter the new row
* or its contents, do it here.
*/
//newRow.cells[0] // first cell
//and then if you access a cell you have the DOM with childNodes,
with
//getElementsByTagName to access stuff in the cell.

//var rn = document.forms["form1"].elements.length;

sect.insertBefore(newRow, row.nextSibling);

row.cells[15].innerHTML = ""
newRow.cells[4].getElementsByTagName("input")[0].value = "";
newRow.cells[11].getElementsByTagName("input")[0].value = "";
newRow.cells[12].getElementsByTagName("input")[0].value =
"1.00";
newRow.cells[13].getElementsByTagName("input")[0].value = "";



}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top