html auto update selection box
Solution 1:
you can try something like this
const targetParent = document.getElementById("sInterval")
["11","12"].forEach(month =>
const optionElement = document.createElement("option")
optionElement.innerText = month;
optionElement.setAttribute("value",month)
targetParent.append(optionElement))
Solution 2:
You need to add the options
to the select
element after updating months
array.
If you are using jQuery
, Then you can simply use append()
method.
var months=["2","3","4","5","6","7","8","9","10"]
function addmonth( month ) {
months.push( month );
$("#sInterval").append(`<option value="${month}"> ${month} </option>`);
}
addmonth("11");
addmonth("12");
Solution 3:
you should change menu all dynamic
in html ) <select id="menu'> </select>
in js - put this code on the <body onload='menu_maker()' >
let month = [1,2,3,4,5,6,7,8,9,10,11,12];
function menu_maker(){
for (var i in month){ // rounding in list
var option = document.createElement("option");
option.value = month[i];
option.innerHTML = month[i];
option.style = 'classname'
var select = document.getElementById('menu');
select.appendChild(option);
}
}