I am working with php and jquery,I am fetching following data in foreach loop
foreach start// "> id;?>"> coin_id;?>"> symbol;?>">
<button id="getinfo" class="votess2" value="1"><img src="<?php echo base_url(); ?>/assets/img/thumb.png" height="40" width="30"></button>
<button id="getinfo" class="votess2" value="0"><img src="<?php echo base_url(); ?>/assets/img/thumbdown.png" height="40" width="30"></button>
</form>
foreach ends//
Now i want to use ajax after click on "like" "dislike" button but giving me always same "reviewId" instead of repeat,Where i am wrong ? Please help ,Thanks in advance
Here is my jquery code
<script type="text/javascript">
$(document).ready(function(){
$(".votess2").click(function()
{
var WalletAddress = document.getElementById("WalletAddress").value;
var ReviewId = document.getElementById("ReviewId").value;
alert(ReviewId );
}
If you are using ID's inside a cicle (ex. foreach) you need to be carefull because the ID's will repeat. You can do set the onclick function on the input inside the foreach.
<?php
foreach($arr as $k=>$v) {
$reviewID = $v->reviewID; //example because i dont know your array structure
?>
<button id="getinfoUp<?=$k?>" onclick="thumbUp(<?=$k?>, <?=$reviewID?>)" class="votess2" value="1"><img src="<?php echo base_url(); ?>/assets/img/thumb.png" height="40" width="30"></button>
<button id="getinfoDown<?=$k?>" onclick="thumbDown(<?=$k?>, <?=$reviewID?>)" class="votess2" value="0"><img src="<?php echo base_url(); ?>/assets/img/thumbdown.png" height="40" width="30"></button>
<?php } ?>
After that you just need to code the functions thumbUp and thumbDown in javascript.