March 28, 2011
reading index value of a table row with many cells and reading the value from it using Jquery
Question by user679460
//PHP array
$Cashups = array(
array(
'cashup_id' => 146456,
'display_time' => 'Wed 16th Mar, 9:55pm',
'terminal_name' => 'Bar 1',
'calculated_cash' => 389.20,
'actual_cash' => 374.6,
'calculated_tenders_total' => 1,551.01,
'actual_tenders_total' => 1,551.01
),
array(
'cashup_id' => 146457,
'display_time' => 'Wed 16th Mar, 9:56pm',
'terminal_name' => 'Bar 2',
'calculated_cash' => 493.3,
'actual_cash' => 493.3,
'calculated_other' => 1509.84,
'actual_other' => 1509.84
)
);
HTML
<?php foreach ($Cashups as $Cashup) { ?>
<tr>
<td class="Left"><?php echo $Cashup['display_time']; ?></td>
<td><?php echo $Cashup['terminal_name']; ?></td>
<td><?php echo number_format($Cashup['calculated_cash'], 2); ?></td>
<td class="clickchange"><a href="#"><?php echo number_format($Cashup['actual_cash'], 2); ?></a></td>
<td><?php echo number_format($Cashup['calculated_other'], 2); ?></td>
<td><?php echo number_format($Cashup['actual_other'], 2); ?></td>
</tr>
<?php } ?>
Jquery
I am able to input text boxes when clicked on the link(clickchange) with the help of an answer sent by user on stackoverflow.
I can read the values but am not able to read the indexes of the links when clicked. I would like to know how to apply each on function to read the indexes of the link. Once I read the inexes I can then update the td with thier respective values.
Please help. How do I read text?
Answer by Starx
I am guessing you want the index when clickChange
is clicked.
$("td.clickchange").click(function() {
var i = $(this).parent("tr").index();
alert(i);
});