Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery event on click

Tags:

jquery

php

I'm having trouble to solve my problem of clicking 5 buttons using Jquery.
I want all 5 buttons clicked, but not at the same time. Instead, I want to execute a button called "Update All". After executing, I want that all 5 buttons get clicked 1 by 1, with 3 seconds gap, then stop at the 5th button.
Here is my code, but this code clicks all buttons, with no interval. So this won't work if the internet is really slow.

Thanks in advance for the Help.
By the way, this code was inside the while loop.

$(document).ready(function(){
    $('#updateAll').click(function(){        
    setTimeout(function() {
        $("#SubmitFormData<?php echo $chili_id; ?>").trigger('click');
    }, 3000);        
  });
});
like image 334
WYD Pilipinas Avatar asked May 29 '26 08:05

WYD Pilipinas


1 Answers

$(document).ready(function(){    
  $('#updateAll').on('click',function(){
     var inputBtn=$('.saveBtn');
     var C=0; 
     var setInter=setInterval(function(){
        if( C==inputBtn.leangh) 
           clearInterval(setInter);  
           $(inputBtn[C]).click(); 
           C++; 
     }, 3000); 
 });
     
    $('.saveBtn').on("click",function(){
     console.log($(this).val());
    });       
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="button" id="updateAll" value="updateAll"/>
<br>
<input type="button" class="saveBtn" value="click 1"/>
<input type="button" class="saveBtn" value="click 2"/>
<input type="button" class="saveBtn" value="click 3"/>
<input type="button" class="saveBtn" value="click 4"/>
<input type="button" class="saveBtn" value="click 5"/>
like image 82
Farhad Bagherlo Avatar answered May 31 '26 10:05

Farhad Bagherlo