I have all of this code that creates new divs and adds innerHTML. Within that, I want to add dropdowns with generated from an XML file. I’m having an issue with dynamically creating the tags inside of inner.HTML.
Now, this is all dynamic and the user is supposed to add new elements as needed. So, as a work around, I have a bunch of var values that process along with each other so things correspond to the same ID’s.
var opselectCounterA = '1';
var opselectCounterB = '1';
var selectCounter = '1';
The tag that I want to add is also within an inner.HTML.
something.innerHTML = "<select id='partSelect" + (selectCounter++) + "'>" + (loadOp) + "</select>";
var selectIDA = "partSelect" + opselectCounterA++;
var selectIDB = "partSelect" + opselectCounterB++;
var loadOp = selectIDA.addOption();
function addOption(){
selectIDB.innerHTML = "<option>Please work.</option>";
}
Whenever this processes on my HTML page, it shows between the tags as “undefined”.
Why for?
There are quite a few things wrong with your code (even though I am only seeing a portion of it).
Regarding the line
var loadOp = selectIDA.addOption();…addOption()which exists on theselectIDAobject. However theselectIDAvariable is actually a string that doesn’t have aaddOption()function. Because javascript doesn’t find a function namedaddOption()on theselectIDAobject, it sets the value of loadOp toundefined.var loadOp = addOption();instead, the value ofloadOpwould still be undefined becauseaddOption()doesn’t return any values.Perhaps you should try something more along these lines…
View the working example on jsFiddle: http://jsfiddle.net/Nxezs/