I would like help in this small problem, I have to do a combobox shows 5 states being loaded by an array in javascript, my code is like this.
HTML
<select >
<option id="estado"></option>
</select>
My Javascript is like this
var select = document.getElementById("estado");
var options = ["São Paulo", "Rio de Janeiro", "Paraná", "Pernambuco", "Rio Grande do Sul"];
for(var i = 0; i < options.length; i++) {
var opt = options[i];
var el = document.createElement("option");
el.textContent = opt;
el.value = opt;
//console.log(el);
select.appendChild(el);
}
Debugging in console.log it brings the cute results as it should be. But at the time of printing the object it brings the following error.
Uncaught TypeError: Can not read property 'appendChild' of null.