The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript What am I doing wrong? Reply To: What am I doing wrong?


If you want to do it via innerHTML, you have to modify your insertion line to:

document.getElementById("demo").innerHTML += "<option>" + options[i] + "</option>";

You were missing the document., because getElementById is a function of the document object. And between innerHTML and the new content you have to add +=, because you want to append the new text to the innerHTML property. And it has to be options[i], since you want to display the value you put into the array, not the index i.

You can see it in action here: