Connecting Tech Pros Worldwide Help | Site Map

Checkbox values to array -- even when not checked

 
LinkBack Thread Tools Search this Thread
  #1  
Old August 17th, 2006, 01:25 PM
Rich_C
Guest
 
Posts: n/a
Default Checkbox values to array -- even when not checked

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 = "";



}
}


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.