I primarily use jQuery, so this is what that would look like. I'll make a codepen too, for you. We've all be new to a language before so I totally get not being able to troubleshoot by yourself!
To clear the list you'll want to do something like this:
$('#hour_interview_ini')
.find('option')
.remove()
.end()
;
And then to add in a loop, you'll want to do this:
for(i = 0; i <= 23; i++){
$('#hour_interview_ini').append('<option value="' + i + '">' + i + '</option>')
}
However, If you want to do it in javascript, this will work too. I put these ones in as functions (although the jquery could be functions too). If you need to know how to call them, check the code pen. It'll show you how to use the function on a click, or how to access the jQuery ID and trigger a function:
Clearing list (not the best method, but works and is super small):
function clearList(){
document.getElementById("hour_interview_ini").innerHTML = "";
}
Adding through the loop
function addList(){
var select = document.getElementById("hour_interview_ini");
for (var i = 0; i<=23; i++){
var opt = document.createElement('option');
opt.value = i;
opt.innerHTML = i;
select.appendChild(opt);
}
}
https://codepen.io/humanhickory/pen/NWKQLyR