I am using an anchor tag for showing dynamic links.I am using javascript function to be called
on anchor onclick.This is working fine.But the issue is that i want to send an array of values to that javascript function.How can i do that? My anchor tag is defined below,
<a onclick="getbatchreport();" id="anch<?php echo "B-" . trim($value['BATCH_NO']); ?>"><?php echo "B-" . trim($value['BATCH_NO']); ?></a>
<?php //stuff and things ?>
<a href='#' onClick='functionName(<?php echo json_encode($arr); ?>)'>Click Me</a>
<script type='text/javascript'>
function functionName(arr){
arr = JSON.parse(arr);
alert(arr[0]);
alert(arr[1]);
alert(arr[2]);
}
</script>
EDIT: Fixed after the author indicated PHP was also involved. Also note that JavaScript handles Associative Arrays weirdly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.