I have found adding inputs to a form is quite simple in Javascript, but for some reason adding the select input with options is not working. The options are appearing outside of the dropdown.
Here's my code in jsfiddle: http://jsfiddle.net/LNVTQ/
Here's my code inline:
var choices=[];
choices[0]="one";
choices[1]="two";
function addInput(divName){
var newDiv=document.createElement('div');
newDiv.innerHTML="<select>";
for(i=0; i<choices.length; i=i+1){
newDiv.innerHTML=newDiv.innerHTML+"<option value='"+choices[i]+"'>"+choices[i]+"</option>";
}
newDiv.innerHTML=newDiv.innerHTML+"</select>";
document.getElementById(divName).appendChild(newDiv);
}
And the HTML:
<form class="new" method="post" action="/jobs">
<div id="dynamicInput"></div>
<input type="button" value="Add" onclick="addInput('dynamicInput');" />
<input type="button" value="Save" />
</form>
I will accept answers using jQuery or just vanilla Javascript.