Show a running clock in html object
Posted: Thu Oct 07, 2021 4:26 pm
I have an issue with updating a value within a html object continously.
I want to show a clock (in a html object) which is updated every second after I pressed a specific button on the form.
Therefore I added following custom code to the button (onclick event):
The correct time is visible in the DIV of my HTML object - but unfortunately only once (and static) and it never will be updated.
I think I'm doing something fundamentally wrong here and hope that someone could help me out please.
Thanks and best regards,
Oli
I want to show a clock (in a html object) which is updated every second after I pressed a specific button on the form.
Therefore I added following custom code to the button (onclick event):
Code: Select all
setTimeout(function(){
var zeit;
var stunden, minuten, sekunden;
var StundenZahl, MinutenZahl, SekundenZahl;
var heute;
heute = new Date();
StundenZahl = heute.getHours();
MinutenZahl = heute.getMinutes();
SekundenZahl = heute.getSeconds();
stunden = StundenZahl+":";
if (MinutenZahl < 10) {minuten = "0" + MinutenZahl + ":";}
else {minuten = MinutenZahl + ":";}
if (SekundenZahl < 10) {sekunden = "0" + SekundenZahl + " ";}
else {sekunden = SekundenZahl + " ";}
zeit = stunden + minuten + sekunden + " Uhr";
document.getElementById('div_time').innerHTML = zeit; // write the current time into the DIV of the html object on the form
},1000);
I think I'm doing something fundamentally wrong here and hope that someone could help me out please.
Thanks and best regards,
Oli