html - Append and remove child elements in javascript if radio button is clicked -


i writing code select database using can show type of query should run. adding queries in select tag using dynamic append() , if change radio button choice select options should changed , every time click radio button previous select tag should removed. have written code it's not appending select child node.please thank you.

var container = document.getelementbyid("container");             if(db == "user")             {                 if(bookq==null)                 {                     bookq = document.getelementbyid ("query2");                     bookq.parentnode.removechild (bookq);                 }                 var array = ["show database","delete record"];                 var selectlist = document.createelement("select");                 selectlist.id = "query1";                 container.appendchild(selectlist);                 (var = 0; < array.length; i++)                  {                     var option = document.createelement("option");                     option.value = array[i];                     option.text = array[i];                     selectlist.appendchild(option);                 }                 userq=null;             }             else              {                 if(userq==null)                 {                     userq = document.getelementbyid ("query1");                     userq.parentnode.removechild (userq);                 }                 var array = ["show database","delete record","insert record"];                 var selectlist = document.createelement("select");                 selectlist.id = "query2";                 container.appendchild(selectlist);                 (var = 0; < array.length; i++)                  {                     var option = document.createelement("option");                     option.value = array[i];                     option.text = array[i];                     selectlist.appendchild(option);                 }                 bookq=null;             } 

wrap code in between

window.onload = function(){   //  code goes here } 

this assure dom objects loaded , ready javascript calls.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -