When I execute the following code, a GET message appears in the Firebug Console however the variable is undefined, and I think that is due to the scope of the variable being limited to the function only.
My goal is to be able to click the table row, and upon clicking the table row, fetch some data from the server related to the record in the table, and then populate part (not all) of a web form, which I will then add more data to, and then submit the form (see image).
Here is the Javascript function which defines a variable called $id as the given rows' data-attribute ('recordID') which itself was been passed into the <tr> tag when the table was generated.
Javascript:
$(document).on('click', 'tr', function() {
//Get the ID from the row clicked
var $id = $(this).data('recordId');
//short-hand
$('#section2').load('data_entry_form.php?id='+id);
});
PHP snippet that includes the data-attribute:
<table = "all_aifs">
<tr>
<th><b>Document ID</b></th>
<th><b>Pubco Name</b></th>
<th><b>Filing Date</b></th>
<th><b>PDF</b></th>
</tr>
<?php foreach($result as $index => $row) : ?>
<tr data-recordId="<?=$row[fee_source_id];?>"
class="<?=$row["match"] ? "match" : "";?>">
<td><?php echo $row[fee_source_id]; ?></td>
<td><?php echo $row[company_name_per_sedar]; ?></td>
<td><?php echo $row[document_filing_date]; ?></td>
<td></td>
</tr>
<? endforeach;?>
</table>
Question: How can I have my web form contain some data related to the row I clicked? I think I need to use AJAX. Also, why is the variable "undefined" in the Console? I think I need it to be defined as the $id variable (which is the recordId).
