I want to pass a php variable into a jquery function parameter, when i added an id to each loop it only return the first one. How to do it right ?
php code :
foreach ($record as $key): ?>
<tr>
<td><a href="" onclick="update_amarta(<?php echo $key->SiteID ?>)"> NOT YET</a></td>
</tr>
<?php endforeach; ?>
Javascript :
<script type="text/javascript">
function update_amarta(id) {
alert(id);
};
</script>
$key->SiteIDis a string you'll need to wrap the ouptut value in quotes. In that case you should see an error in the console when you attempt to click the element.alert()for troubleshooting., useconsole.log()instead.