var idinterval;
var second_input = document.getElementById("Seconds");
var minute_input = document.getElementById("Minutes");
var second_value = second_input.value;
var minute_value = minute_input.value;
var total = parseInt(minute_value * 60) + parseInt(second_value);
function starter() {
if (total > 0) {
total = total - 1;
document.getElementById("timing").innerHTML = Math.floor(total / 60) + ":" + total % 60;
return;
}
}
function start_the_timer() {
setInterval(() => {
starter();
}, 1000);
}
::placeholder {
font-size: 20px;
}
.Starter {
color: white;
width: 120px;
height: 37px;
padding: 6px;
font-size: 15px;
background-color: rgb(21, 27, 84);
margin-top: 30px;
margin-right: 5px;
}
.Starter:hover {
background-color: #0000B9;
}
.Pauser {
color: white;
width: 120px;
height: 37px;
padding: 6px;
font-size: 15px;
background-color: #767676;
margin-top: 30px;
margin-right: 5px;
}
.Pauser:hover {
background-color: #444444;
}
.Stopper {
color: white;
width: 120px;
height: 37px;
padding: 6px;
font-size: 15px;
background-color: #B2B2B2;
margin-top: 30px;
margin-right: 5px
}
.Stopper:hover {
background-color: #303030;
}
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="timer.css" />
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Clockworks</title>
</head>
<body>
<script src="timer.js" type="text/javascript"></script>
<div style="margin-top:50px;margin-left:50px;">
<h1 style="font-size: 60px; color: black;font-weight: bold;">Clockworks</h1>
<hr style="transform: rotate(90deg);margin-left:350px;width:200px ">
<form id="timer_form">
<label style="font-size: 30px; font-weight:100; font-style: italic; margin-bottom: 500px;width:5px">
Minutes <input id="Minutes" value="0" placeholder="00" style="font-size:20px;background-color:transparent;margin-left: 10px; color:black;height:30px; width: 200px;border-top: none;border-left: none;border-right: none;border-bottom: 1px solid black;" type="number" min="1 " max="2000000">
</label>
<br><br>
<label style="font-size: 30px; font-weight:100; font-style: italic; margin-top: 100px ;">
Seconds
<input id="Seconds" placeholder="00" value="0" style="font-size:20px;background-color:transparent;margin-left: 10px; color:black;height:30px; width: 200px;border-top: none;border-left: none;border-right: none;border-bottom: 1px solid black;" type="number" min="1 " max="2000000">
</label></form>
<br>
<button class="Starter" id="start" type="button" onclick="start_the_timer()">Start</button>
<button class="Pauser" id="pause" type="button" onclick="stop()">Pause</button>
<button class="Stopper" id="stop" type="button" onclick="reset()">Stop</button>
<p id="timing" style="font-weight: 600;font-size:100px; position:relative; bottom:300px; left:500px;">00:00</p>
</div>
</body>
</html>
Note: this is a simple function for a timer that gets the minutes and seconds from a user in an html input text ,this is the error shown in dev tools after executing the code
can anyone tell me the cause of my problem?
Uncaught TypeError: second_input is null
Note: the problem is caused only in JavaScript code. I tried to change the value of minute_input and second_input to any int and it worked