I have made a countdown in html and javascript. However, I need it to refresh every second for the seconds in the time, but I do not want the whole page to refresh. I have tried:
<meta http-equiv="refresh" content="1">
However, this refreshes the whole page and not just the section that I need to. Is it possible to just refresh the div. Or is there another way that I can get the page to update each second without refreshing. I have tried to look for answers, however, they all involve php and I don't yet know how to use it. Any help would be appreciated. This is my html and javascript so far:
<p>Date: <span id="date"></span></p>
<p>Time: <span id="time"></span></p>
<p>Countdown Time: <span id="release"></span></p>
<p id="timeuntil">Time Until:
<span id="secs"></span><span id="sectxt"></span>
<span id="mins"></span><span id="mintxt"></span>
<span id="hours"></span><span id="hourtxt"></span>
</p>
<script>
var ct = new Date();
var dt = new Date("2021-03-19:015:00");
var ctsecs = ct.getSeconds(); var dtsecs = dt.getDate();
var tusecs = dtsecs - ctsecs; var secs_text;
var ctmins = ct.getMinutes(); var dtmins = dt.getMinutes();
var tumins = dtmins - ctmins; var month_text;
var cthour = ct.getHours(); var dthour = dt.getHours();
var tuhour = dthour - cthour; var hour_text;
//Fixing -ve values
if (tusecs < 0){tusecs = tusecs + 30; tumins = tumins - 1;}
if (tumins < 0){tumins = tumins + 12; tuhour = tuhour - 1;}
if (tuhour == 1){hour_text = " hour";} else {hour_text = " hours";}
if (tumins == 1){mins_text = " minute, ";} else {mins_text = " minutes, ";}
if (tusecs == 1){secs_text = " second, ";} else {secs_text = " seconds, ";}
//Defining "Now" and "In the Past"
if (tusecs + tumins + tuhour == 0){tusecs="";sec_text="";tumins="";
mins_text="";tuhour = "";hour_text = "NOW";}
if (tusecs<0 || tumins<0 || tuhour<0){tusecs="";secs_text="";tumins="";
mins_text="";tuhour = "";hour_text = "In The Past";}
document.getElementById("date").innerHTML = ct.toLocaleDateString();
document.getElementById("time").innerHTML = ct.toLocaleTimeString();
document.getElementById("release").innerHTML = dt.toLocaleDateString();
document.getElementById("secs").innerHTML = tusecs;
document.getElementById("sectxt").innerHTML = sec_text;
document.getElementById("mins").innerHTML = tumins;
document.getElementById("mintxt").innerHTML = mins_text;
document.getElementById("hours").innerHTML = tuhour;
document.getElementById("hourtxt").innerHTML = hour_text;
</script>