Hello,
I'm trying to do a javascript function which will create a new div called "myDiv1", "myDiv2" depending on how many enitities the user chooses, that contains a table which contains a select tag.
This new div will be appended to an established div called "divPlaceSpecDep" (static div already placed on the page).
I've previously done this by just building the innerHTML, appending to it, and rebuilding it every time the user chooses a new entity. HOwever, this time I'm trying to use the document.createElement function, as it's seeming a little easier to work with.
The output per entity I want is like this:
I already have the code that creates the select tag with the options by using the document.createElement function. Then I use divPlaceSpecDep.appendChild to add it to my html.
Now I just need to get it into a more tabular format so it looks nice.
My question is how to mix the document.createElement and div.innerHTML effectively? I tried to create a table element then append the select tag to it but it wasn't working.
Does anyone have a simple example for what I'm trying to do?
Thanks in advance.
I'm trying to do a javascript function which will create a new div called "myDiv1", "myDiv2" depending on how many enitities the user chooses, that contains a table which contains a select tag.
This new div will be appended to an established div called "divPlaceSpecDep" (static div already placed on the page).
I've previously done this by just building the innerHTML, appending to it, and rebuilding it every time the user chooses a new entity. HOwever, this time I'm trying to use the document.createElement function, as it's seeming a little easier to work with.
The output per entity I want is like this:
Code:
<div id="myDiv1">
<table>
<tr><td>myEntity1</td></tr>
<tr><td><select id="mySelect1">
<option value=1>option1Text</option>
<option value=2>option2Text</option>
</select></td></tr>
</table>
</div>
I already have the code that creates the select tag with the options by using the document.createElement function. Then I use divPlaceSpecDep.appendChild to add it to my html.
Now I just need to get it into a more tabular format so it looks nice.
My question is how to mix the document.createElement and div.innerHTML effectively? I tried to create a table element then append the select tag to it but it wasn't working.
Does anyone have a simple example for what I'm trying to do?
Thanks in advance.