0

I have a javascript code like this for auto clicking submit button after 2 hours.

<script>
setTimeout(function() {   //calls click event after a certain time
 $('.submit-button').click();
}, 1442628010000);
</script>

But the problem is the button is clicked immedialy after page is load :(

But when i do for 10 sec it works :(

<script>
setTimeout(function() {   //calls click event after a certain time
 $('.submit-button').click();
}, 10000);
</script>

I even tried like this but not working

<script>
setTimeout(function() {   //calls click event after a certain time
 $('.submit-button').click();
}, 2*60*60*1000); //2h
</script>

Now what should i do to click the button if settimeout is not working?

user80946
  • 355
  • 1
  • 3
  • 9
  • 2
    http://stackoverflow.com/questions/3468607/why-does-settimeout-break-for-large-millisecond-delay-values – sinisake Sep 19 '15 at 14:52
  • 2
    You do realize that 1442628010000 milliseconds is, very roughly, 45.7 ***years***? – T.J. Crowder Sep 19 '15 at 14:52
  • 3
    2 hours is equal to 7.200.000 – kakajan Sep 19 '15 at 14:55
  • https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setTimeout – AlexStack Sep 19 '15 at 14:57
  • Just to be clear re @kakajan's comment: Two hours in milliseconds: 2 x 60 x 60 x 1000 = 7,200,000 (, = thousands separator). The value to use in code is 7200000. 2 hours x 60 gives us 120 minutes. 120 minutes x 60 gives us 7,200 seconds. 7,200 x 1000 gives us 7,200,000. – T.J. Crowder Sep 19 '15 at 14:57
  • @nevermind Sorry thought my calculation was mistake 2 hour is 72 x 10 ^ 5. But what am i supposed to do now to click the button automatically after suppose 10 hour ? – user80946 Sep 19 '15 at 14:59
  • What are you supposed to do? Do the math. – T.J. Crowder Sep 19 '15 at 14:59
  • 1
    I hate math, too - http://www.convertworld.com/en/time/Milliseconds.html :) – sinisake Sep 19 '15 at 15:00
  • @T.J.Crowder Soory for wrong calculation ..I tried over 100 times so that may be reason it was mistake :( but is there anyway to click button except settimeout which is not supposed to be working ? – user80946 Sep 19 '15 at 15:01
  • 1
    @user80946: The above will click the button. Whether the browser lets that do whatever it is the button does is another question entirely. I, for one, would have a ***major*** problem with any website or web application that lurked for two hours before doing anything significant (like submitting a form). – T.J. Crowder Sep 19 '15 at 15:05
  • @T.J.Crowder Yes i am trying to submit form form after 72 x 10 ^ 5 seconds. Isn't it possible from settimeout? – user80946 Sep 19 '15 at 15:11
  • @user80946, it seems that 10 hours is in bounds of setTimeout()... http://jsfiddle.net/djasm8nL/ however, wouldn't wait 10 hours to check. :) It is not clicked at page load, so... should work. :) – sinisake Sep 19 '15 at 15:15

0 Answers0