001
001

Reputation: 65205

How to click a browser button with JavaScript automatically?

How to click a button every second using JavaScript?

Upvotes: 58

Views: 169060

Answers (6)

nikunj
nikunj

Reputation: 33

this will work ,simple and easy

<form method="POST">
  <input  type="submit" onclick="myFunction()" class="save" value="send" name="send" id="send" style="width:20%;">
</form>
<script language ="javascript" >
  function myFunction() {
    setInterval(function() {
      document.getElementById("send").click();
    }, 10000);    
  }
</script>

Upvotes: 0

John Hartsock
John Hartsock

Reputation: 86902

setInterval(function () {document.getElementById("myButtonId").click();}, 1000);

Upvotes: 127

Footer
Footer

Reputation: 139

You can use

setInterval(function(){ 
    document.getElementById("yourbutton").click();
}, 1000);

Upvotes: 2

Meuru Muthuthanthri
Meuru Muthuthanthri

Reputation: 86

This would work

setInterval(function(){$("#myButtonId").click();}, 1000);

Upvotes: 2

Isaac
Isaac

Reputation: 11805

This will give you some control over the clicking, and looks tidy

<script>
var timeOut = 0;
function onClick(but)
{
    //code
    clearTimeout(timeOut);
    timeOut = setTimeout(function (){onClick(but)},1000);
}
</script>
<button onclick="onClick(this)">Start clicking</button>

Upvotes: 7

KonaRin
KonaRin

Reputation: 99

document.getElementById('youridhere').click()

Upvotes: 5

Related Questions