Ok, I know how to do this – in theory. I have a dropdown list in a web page that I want to edit dynamically with javascript. My dropdown list has been created, empty, with the following HTML:
<select id="my_dropdown">
</select>
and then this javascript code (run in the head section) is supposed to fill it in with a single option:
my_drop = document.getElementById("my_dropdown");
my_drop.options[0] = new Option("Name", "value");
I think I’m doing everything by the books but, even stripped to the bone at this point, this code still doesn’t work, either on Chromium or Firefox. I have no idea what to try next. Suggestions?
If you’re doing it in the head, ouside of any
onloadhandler, then the DOM is not ready yet.Either move your javascript to after the element in the HTML, or enclose it in an
onloadfunction.eg/
and in the head