Reputation: 35
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);
});
});
Upvotes: 3
Views: 83
Reputation: 139
var i=1;
$(document).ready(function() {
$("#update").click(function(){
interval = setInterval(function(){
if(i<=5)
{
$("#"+i).click();
alert("button"+i+"click");
}
i++;
},3000);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="button" id="update" class="btn" value="Update All"/>
<br/><br/><br/>
<input type="button" id="1" class="btn" value="click 1"/>
<input type="button" id="2" class="btn" value="click 2"/>
<input type="button" id="3" class="btn" value="click 3"/>
<input type="button" id="4" class="btn" value="click 4"/>
<input type="button" id="5" class="btn" value="click 5"/>
Upvotes: 0
Reputation: 6699
$(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"/>
Upvotes: 2