Skip to content Skip to sidebar Skip to footer

Creating Dropdown Dynamically - Javascript

I'm trying to develop a JS function that creates a new row each time a new record is added to a database (from a different program that checks periodically). Right now I can get th

Solution 1:

After

textnode2 = document.createElement("select");

you need to do something like

var op = new Option();
op.value = 1;
op.text = "First entry";
textnode2.options.add(op);      

and repeat for your desired entries.

Solution 2:

I like this method.

var dropdown = document.getElementById("MyDropDownList");
var opt = document.createElement("option"); 
opt.text = 'something';
opt.value = 'somethings value';
dropdown.options.add(opt);

Post a Comment for "Creating Dropdown Dynamically - Javascript"