jQuery: The Write Less, Do More JavaScript Library

jQuery Countdown and close button

View: New views
3 Messages — Rating Filter:   Alert me  

jQuery Countdown and close button

by Met00 - Met00Cigar :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I know I'm missing something obvious. the "Close" button is supposed
to stop both countdown timers and manually toggle the quiz to the quiz
complete div. It doesn't. So what simple thing am I missing here. :-)

###

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>jQuery ui test</title>
<script type="text/javascript" src="/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="/js/jquery.countdown.min.js"></
script>
<style type="text/css">@import "/css/jquery.countdown.css";
#quizCountdown { width: 440px; height: 45px; }
#quizCountdown2 { display: none; width: 440px; height: 45px; }
#quizc { display: none; }
</style>
<script type="text/javascript">
$(function () {
var aDay = new Date();
aDay = '+3s';
$('#quizCountdown').countdown({until: aDay,
 description: 'Countdown is informational only, server times are used.
<b>Do not reload the page</b>',
 layout: 'Quiz Time Remaining: {mn} {ml}, {sn} {sl} ',
 onExpiry: liftOff
});
});
function liftOff() {
var bDay = new Date();
bDay = '+5s';
$('#quizCountdown2').countdown({until: bDay,
 description: 'Countdown is informational only, server times are used.
<b>Do not reload the page</b>',
 layout: '<font color=red>Overtime Quiz Time Remaining: {mn} {ml},
{sn} {sl} </font>',
 onExpiry: liftoff2
});
    $("#quizCountdown, #quizCountdown2").toggle();
}
function liftoff2() {
  $("#quiz, #quizc, #quizCountdown2").toggle();
}
$('#closeButton').click(function() {
                $('#quizCountdown').countdown('destroy');
                $('#quizCountdown2').countdown('destroy');
                $("#quiz, #quizc").toggle();
        }
);
</script>
</head>
<div id="quizCountdown"></div>
<div id="quizCountdown2"></div>
<div id=quiz>This is the quiz<div><button type="button"
id="closeButton">Close</button></p>
</div></div>
<div id=quizc><b>The quiz is completed</b><p>Please click on the
Continue button below to load the problems and their solutions.</div>

Re: jQuery Countdown and close button

by Doug Nelson-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


It looks like neither the Quiz or Quizc div ids have quotes around
them...could that be it?


Re: jQuery Countdown and close button

by Keith-117 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


The problem is that the closeButton setup is called immediately it is
encountered - before the button itself exists - so no match and
nothing happens. You need to move the $('#closeButton').click(function
() { ... }); inside the document ready call: $(function () { ...}).