I am trying to store multiple text values into an array when a check box is checked.
for example when row1 checkbox is checked the values row1col1 and row1col2 are stored in an array. note however row1col1 and row1col2 are editable and not readonly.
for example:

<table border="1"> <form id="form1" name="form1" method="post" action="">   
<td>row1       <input type="checkbox" name="row1" id="row1" /> (when checked the text fields are editable)         </td>   
  <td>       <input name="col1" type="text" id="col1" value="row1col1" /></td>    
 <td>       <input name="col2" type="text" id="col2" value="row1col2" /></td>  </tr>     
 <tr>     <td>row2       <input type="checkbox" name="row2" id="row2" />(when checked the text fields are editable)            </td>     
<td>       <input name="r2c1" type="text" id="r2c1" value="row2col1" /></td>    
 <td>       <input name="r2c2" type="text" id="r2c2" value="row2col2" /></td>  </tr>  

can anyone help?


It depends on the purpose of the array.

Is is to store a snapshot or the history of values in the input fields?

  • Snapshot: We would overwrite each entry when it is updated.
  • History: We would add new entries without destroying anything.


Thanks Airshow for you interest.

I would like store a snapshot of the values, or to put it across better: I would like to store the values of the "checked row" at the time of submission.

Hope that explains it better.

With a regular HTML form submission the whole page (including the javascript environment) will be refreshed, hence any javascript arrays/values/objects will be lost and unavailable to the refreshed page.

There's are number of possible solutions :

  • Save the values in a cookie and read them back. This is fairly easy but not a particularly good solution.
  • Make an AJAX request instead of submitting the form. This would be a major change as it would require server-side as well as client-side programming. The advantage would be that the page remains intact, therfore no need to save/recreate your "checked row" status as it's already very reliably stored in the DOM (the checkboxes themselves).
  • Server-side, write the page with apprioriate rows already checked. This is the solution to go for if you are going to stick with a regualr form submission.