Home › Forums › JavaScript › What am I doing wrong? › Reply To: What am I doing wrong?
August 8, 2013 at 3:14 am
#146103
Participant
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: http://codepen.io/anon/pen/HCAIt