Reputation: 624
Hello i want to create dynamic drop-downs using javascript, but its not working..
My PHP code:
<input type="button" onclick="javascript:addRow();" value="Add Row" name="addRow"/>
My JS code:
// This function is used to create dynamic form element
function addRow() {
var opt = document.createElement("option");
element = document.createElement("select");
element.setAttribute('id', 'focus');
element.options.add(opt);
}
PS: It is not giving any js console error.
Upvotes: 0
Views: 129
Reputation: 2222
you dont add the element to the body so it doesn't show up
// This function is used to create dynamic form element
function addRow() {
var opt = document.createElement("option");
element = document.createElement("select");
element.setAttribute('id', 'focus');
element.options.add(opt);
document.body.appendChild(element);
}
Upvotes: 3