Note that there are some explanatory texts on larger screens.

plurals
  1. POShow a countdowntimer-script with DOM
    primarykey
    data
    text
    <p>I'm fairly new to DOM and the whole HTML and PHP Stuff so I'm seeking some information on how to do this. What I have until now is a Javascript. Now I want/have to use DOM to show this script. (FYI: I'm implementing something for Moodle and this has be done like this)</p> <p>What I have found out about DOM is that I can change values of different Nodes. The problem I've found myself in is that all the examples I found were like. Click on a button and something happens. That's ok but now I want my script to run every second so I can the person who needs it can see that the time is running down.</p> <p>I hope I gave you enough information and I hope you can help me. Thank you for trying to help me. </p> <pre><code>var running = false var endTime = null var timerID = null // totalMinutes the amount of minutes is put into var totalMinutes = 3; function startTimer() { // running is being started and the current time is put into the variable running = true now = new Date() now = now.getTime() // Variable endTime gets the time plus the maximum time endTime = now + (1000 * 60 * totalMinutes); showCountDown() } function showCountDown() { // same as startTimer, time is saved in variable now var now = new Date() now = now.getTime() if (endTime - now &lt;= 0) { // Variable timerID gets clearTimeout --&gt;http://de.selfhtml.org/javascript/objekte/window.htm#clear_timeout clearTimeout(timerID) // boolean running set to false running = false alert("Ihr Resultat wird nun ausgewertet!") } else { // delta is being calculated var delta = new Date(endTime - now) var theMin = delta.getMinutes() var theSec = delta.getSeconds() var theTime = theMin // show seconds and minutes theTime += ((theSec &lt; 10) ? ":0" : ":") + theSec document.getElementById('CheckResults').innerHTML = " (&amp;Uuml;bung in " + theTime + " Minuten abgelaufen)" if (running) { timerID = setTimeout("showCountDown()",900) } } } &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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