jQuery Table - Reference User Input Row Names and Values

Posted by Vic on Stack Overflow See other posts from Stack Overflow or by Vic
Published on 2010-05-26T21:40:12Z Indexed on 2010/05/26 21:41 UTC
Read the original article Hit count: 273

Filed under:
|
|

I have several tables which are generated by another application, which I have no control over. I am totally new to jQuery and ajax, and have only a limited knowledge of jsp. Two sample rows are:

<table class="sicknessForm">                  
<tr id="row_0" class="datarow">
 <td id="col_2"><input name="row_0-col_2"  class="tabcell" value="Injuries"></td>
 <td id="col_4"><input name="row_0-col_4"  class="tabcell" value="01"></td>
 <td id="col_5"><input name="row_0-col_5"  class="tabcell" value="2"></td>
 <td id="col_6"><input name="row_0-col_6"  class="tabcell" value="5"></td>
</tr>  

<tr id="row_1" class="datarow">
 <td id="col_2"><input name="row_1-col_2"  class="tabcell" value="Absences"></td>
 <td id="col_4"><input name="row_1-col_4"  class="tabcell" value="100"></td>
 <td id="col_5"><input name="row_1-col_5"  class="tabcell" value="102"></td>
 <td id="col_6"><input name="row_1-col_6"  class="tabcell" value="105"></td>
</tr>  
</table>

There are more rows and columns in the actual tables. What I need to do is to pass the ordered row information to the database, e.g.:
Injuries, 1, 2, 5 ....
Absences 100, 102, 105...

I can retrieve the values for each input using:

 $('#SicknessForm .userInput').each(function() {
  alert($(this).val());
 });

1) How can I loop through each row, get the value from the first column (Injuries) and place the data into an array to send to the server? 2) How do I reference the first row of each column to disable user input on it?
$(:HowDoIReferenceThis).attr('disabled', ''); 3) I need to validate that each cell is numeric, other than the first column. Any pointers on this (otherwise I can check it in my servlet), especially on how to loop through all valid input cells (everything except 'Injuries','Abences', ... cells).

Many Thanks! Vic

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about table