how to get the value of the count timer on button click?

Arun Kumaresh
<script>
function startTimer(duration, display) {
    var timer = duration, minutes, seconds;
     interval = 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) {
            alert("Time has ended");
            $("#registration-form").submit()
            clearInterval(interval);
          }
        }, 1000);
}

 jQuery(function ($) {
    s=10;
    var Minutes = 60 * s,
    isplay = $('#time');
    startTimer(Minutes, display);
});
</script>

<div class="col-md-4">
  <div class="test" >Time Left <span id="time"></span>min</div>
</div>

<form name="frmRegistration" id="registration-form" method="post">
  <input class="btnAction" type="submit" name="finish" id="finish" value="Finish" onclick="clearInterval(interval)" style="display:none;">
</form>

This is my countdown timer when the page loads the timer will start when i click the button i should get the value of how many minutes the timer has run for example if the timer is run for 2 min i should get the value as 2 min and i want it store it in the database i have tried the following but it doesnt work please hlep

Rory McCrossan

The easiest and most reliable way would be to store the date the timer started in a variable, then get the difference between that date and the current date when the button is clicked, something like this:

$('button').click(function() {
    var now = new Date();
    var seconds = (now.getTime() - startDate.getTime()) / 1000;
    $('#runtimes').append('<p>' + seconds + '</p>');
});

Working example

This shows the value in seconds, but this can easily be converted to minutes and rounded up or down as you require.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how to get the value of the count timer on button click?

From Dev

how to get the value from button on click

From Dev

How to get value of input button click?

From Dev

How to get table cell value on button click

From Dev

How to get a value where button click?

From Dev

How to get the count of checked rows of a table on a button click using jQuery?

From Dev

How to stop timer affacted by button click?

From Dev

How to get a value of the closest td with class on button click?

From Dev

how to get the value of a function from a button click in javascript?

From Dev

How can i get the text box value on click button?

From Dev

How I get input value when button is click

From Dev

how to get the specific row value from corresponding button click in gridview

From Dev

How to get textbox value via button click Ajax

From Dev

React native:how to get Text value on a button click?

From Dev

Start timer on button click

From Dev

How to change the value of button on click?

From Dev

How to give a value / get a value from a timer

From Dev

How to get notification on Button Click?

From Dev

Getting issue in latest versions How to get side power button click count in android app?

From Dev

RxJS -- How to make a timer trigger by click a button when using RxJS?

From Dev

How can get the value of Radio Button Inside Listview Click on Button in Android

From Dev

Android: Get Textview value of Spinner on Button click

From Dev

ExtJS - Get a selected value of a grid on a click of a button

From Dev

JQuery - Click Submit Button Get Form Value

From Dev

Get variable input value on button click

From Dev

jQuery get input value on button click

From Dev

Get variable input value on button click

From Dev

Get the value of label assigned by jquery in a button click

From Dev

javascript - get the correct value of the button on click

Related Related

  1. 1

    how to get the value of the count timer on button click?

  2. 2

    how to get the value from button on click

  3. 3

    How to get value of input button click?

  4. 4

    How to get table cell value on button click

  5. 5

    How to get a value where button click?

  6. 6

    How to get the count of checked rows of a table on a button click using jQuery?

  7. 7

    How to stop timer affacted by button click?

  8. 8

    How to get a value of the closest td with class on button click?

  9. 9

    how to get the value of a function from a button click in javascript?

  10. 10

    How can i get the text box value on click button?

  11. 11

    How I get input value when button is click

  12. 12

    how to get the specific row value from corresponding button click in gridview

  13. 13

    How to get textbox value via button click Ajax

  14. 14

    React native:how to get Text value on a button click?

  15. 15

    Start timer on button click

  16. 16

    How to change the value of button on click?

  17. 17

    How to give a value / get a value from a timer

  18. 18

    How to get notification on Button Click?

  19. 19

    Getting issue in latest versions How to get side power button click count in android app?

  20. 20

    RxJS -- How to make a timer trigger by click a button when using RxJS?

  21. 21

    How can get the value of Radio Button Inside Listview Click on Button in Android

  22. 22

    Android: Get Textview value of Spinner on Button click

  23. 23

    ExtJS - Get a selected value of a grid on a click of a button

  24. 24

    JQuery - Click Submit Button Get Form Value

  25. 25

    Get variable input value on button click

  26. 26

    jQuery get input value on button click

  27. 27

    Get variable input value on button click

  28. 28

    Get the value of label assigned by jquery in a button click

  29. 29

    javascript - get the correct value of the button on click

HotTag

Archive