javascript - how can activate my countdown timer with button? -


i have countdown timer function writed in javascript.its working starts when start page.i want should start when button clicked.

  function starttimer(duration, display) {         var timer = duration, minutes, seconds;         setinterval(function () {              minutes = parseint(timer / 60, 10);             seconds = parseint(timer % 60, 10);              minutes = minutes < 10 ? "0" + minutes : minutes;             seconds = seconds < 10 ? "0" + seconds : seconds;              display.text(minutes + ":" + seconds);              if (--timer < 0) {               //  timer = 0;                  time.style.display = "none";                 time2.style.display2 = "none";                 redxsms.style.display = "none";                 onaysms.style.display = "none";                 tekraruyarionay.style.display = "block";                 tekraruyarired.style.display = "block";                  // time.style.display="block";                 settimeout(function () { location.reload() }, 5000);             }         }, 1000);     }       jquery(function ($) {         var fiveminutes = 60 * 3,             display = $('#time');         display2 = $('#time2');         starttimer(fiveminutes, display);         starttimer(fiveminutes, display2);      }); 

this countdown function.

  <button class="ui toggle button" onclick="      hideshow(document.getelementbyid('onaysms')); show(this);" id="onaytoggle"> 

this button when click should activate.

<span id="time"></span> 

it starts when page start how can start when button clicked?

insert timer call in "onclick" event this, fired when click on button.

if have several buttons on page, advise give 1 id adding in html : id='timertoggle' , replacing $("button.toggle") in code below $("#timertoggle")

 jquery(function ($) {            $("button.toggle").click(function(){                var fiveminutes = 60 * 3,                    display = $('#time');                display2 = $('#time2');                starttimer(fiveminutes, display);                starttimer(fiveminutes, display2);            });         }); 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -