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>
1 Answer 1
Hi @highcal please use this PHP code inside inverted comma's. something like that
<a href="" onclick="update_amarta('<?php echo $key->SiteID ?>')"> NOT YET</a>
Hope this will work for you. Thank You.
answered Oct 25, 2018 at 12:39
Videsh Chauhan
3712 silver badges19 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
ADyson
you might want to explain why you think your answer will help (although of course it is based on an assumption about the data type). That would be much better for those reading it.
default
$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.