Creating Dropdown Dynamically - Javascript

前端 未结 2 719
情话喂你
情话喂你 2020-12-19 15:22

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 ca

相关标签:
2条回答
  • 2020-12-19 15:47

    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.

    0 讨论(0)
  • 2020-12-19 15:49

    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);
    
    0 讨论(0)
提交回复
热议问题