0

I'm using the keith-wood Countdown in the following script.

<script type="text/javascript" src="jquery.countdown.js"></script>
<script type="text/javascript">
$(function () {
    $('#defaultCountdown').countdown({
        until: +60,
        format: 'yodhmS',
        layout: '{y<}{yn}a, {y>}{o<}{on}m, {o>}{d<}{dn}g, {d>}{h<}{hn}o, {h>}{m<}{mn}m, {m>}{s<}{snn}s{s>}'
    });
});

I want to reset the countdown when the user clicks Reset button. I've tried the following solution but it doesn't work. I get the following error: "Uncaught Unknown command: change"

$(document).ready(function() {
    $('#reset').click(function() {
        $('#defaultCountdown').countdown('change', {until: +60});
    });
});
</script>

<div id="defaultCountdown"></div>
<input type="button" id="reset" value="Reset" />

Can someone help me? Thank you!

2 Answers 2

1

You must not use change (this is not defined. Use option instead:

$('#reset').click(function() {
    $('#defaultCountdown').countdown('option', { until: +60 });    
});
1

'change' should be 'option', which will restart the counter at 60 seconds when the reset button is clicked:

$('#reset').click(function() {
   $('#defaultCountdown').countdown('option', {until: +60});
});

In full:

<div id="defaultCountdown"></div>
<input type="button" id="reset" value="Reset" />

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" src="jquery.countdown.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
    $('#defaultCountdown').countdown({
        until: +60,
        format: 'yodhmS',
        layout: '{y<}{yn}a, {y>}{o<}{on}m, {o>}{d<}{dn}g, {d>}{h<}{hn}o, {h>}{m<}{mn}m, {m>}{s<}{snn}s{s>}'
    });

    $('#reset').click(function() {
        $('#defaultCountdown').countdown('option', {until: +60});
    }); 
});
</script>
1
  • Sorry for duplicating - Mark's solution appeared as I posted mine.
    – Tim Carr
    Oct 2, 2012 at 10:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.