Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

102
Views
How to get dynamic id of div using loop in jquery

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 );

}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!