I've used this site a ton but this is the first time posting. Please be kind. I'm trying to pass data from an HTML table to a function using onclick. I'm able to pass the entire table using onclick="markPaid(transaction.innterText)
, but I want to be able to pass the data from the current data row only. My best attempt is onclick="markPaid(thistransaction.innterText)"
but results in an undefined variable when passed to the function "markPaid". Hopefully this is a clear explanation of the issue.
<table id ="transaction" border="1">
<style>th, td {padding: 10px;}</style>
<thead>
<tr>
<th><?php echo implode('</th><th>', array_keys(current($transactions))); ?></th>
<th></th>
</tr>
</thead>
<tbody>
<?php foreach ($transactions as $transaction): array_map('htmlentities', $transaction); ?>
<tr>
<td id = "thistransaction"><?php echo implode('</td><td>', $transaction); ?></td>
<td><a class ="btn btn-default" href="invoice.php?ID=<?php echo $transaction['transid']; ?>" target = "_blank">Print Invoice</a> </td>
<?php if($transaction['paid'] == false): ?>
<td><button class = "btn btn-default" onclick="markPaid(thistransaction.innterText)">Mark as Paid</button></td>
<?php endif; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>