I have a script
<input type="text" value="0" id="count_id">
<input type="button" value="Click Me" id="button_id" onclick="myFunction()">
<script>
function myFunction() {
var data = document.getElementById("count_id").value;
var datacount = (parseInt(data) + 1);
document.getElementById("count_id").value = datacount;
document.getElementById("button_id").value = "Clicked";
}
setInterval(function(){
document.getElementById("button_id").click();
}, 3000);
}
</script>
by using this they click on button every 3 seconds
I want they click on button only 2 time then stop but they click again again and again
Help me here
2
Answers
You can make a counter and check the condition by the counter value and if the button is clicked 2 times then you can clear the intervak
You would need a variable to count the number of clicks. Here’s an example: