Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to make countdown timer to not reset on page refresh
    primarykey
    data
    text
    <p>I am creating an online exam page for my project. I have a countdown timer, but it resets on page refresh. How can I make it not to reset? The timer is set by fetching time from db. I am using php mysql. Please help me. Here is my code.</p> <pre><code>&lt;?php $result=mysql_query("select * from test where testid='29'"); while($time=mysql_fetch_array($result)){ $dateFormat = "d F Y -- g:i a"; $targetDate = time() + ($time['duration']*60); $actualDate = time(); $secondsDiff = $targetDate - $actualDate; $remainingDay = floor($secondsDiff/60/60/24); $remainingHour = floor(($secondsDiff-($remainingDay*60*60*24))/60/60); $remainingMinutes = floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))/60); $remainingSeconds = floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))-($remainingMinutes*60)); $actualDateDisplay = date($dateFormat,$actualDate); $targetDateDisplay = date($dateFormat,$targetDate); } ?&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;Untitled Document&lt;/title&gt; &lt;script type="text/javascript"&gt; var days = &lt;?php echo $remainingDay; ?&gt; var hours = &lt;?php echo $remainingHour; ?&gt; var minutes = &lt;?php echo $remainingMinutes; ?&gt; var seconds = &lt;?php echo $remainingSeconds; ?&gt; function setCountDown () { seconds--; if (seconds &lt; 0){ minutes--; seconds = 59 } if (minutes &lt; 0){ hours--; minutes = 59 } if (hours &lt; 0){ hours = 23 } document.getElementById("remain").innerHTML = " "+hours+" hr "+minutes+" min "+seconds+" sec"; SD=window.setTimeout( "setCountDown()", 1000 ); if (minutes == '00' &amp;&amp; seconds == '00') { seconds = "00"; window.clearTimeout(SD); window.location = "result.php" } } &lt;/script&gt; &lt;/head&gt; &lt;body onLoad="setCountDown();"&gt; &lt;div id="remain"&gt; &lt;?php echo "$remainingHour hours, $remainingMinutes minutes, $remainingSeconds seconds";?&gt; &lt;/div&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload