title: Append and remove child elements in javascript if radio button is clicked
body: <p>I am writing code to <code>select</code> a database using which I can show which type of query should be run. I am adding queries in select tag using dynamic <code>append()</code> and if I change the radio button choice select options should be changed and every time I click the radio button the previous select tag should be removed. I have written the code but it's not even appending the select child node.Please help
  Thank you.</p>
  
  <pre><code>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);
                  for (var i = 0; i &lt; 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);
                  for (var i = 0; i &lt; array.length; i++) 
                  {
                      var option = document.createElement("option");
                      option.value = array[i];
                      option.text = array[i];
                      selectList.appendChild(option);
                  }
                  bookq=null;
              }
  </code></pre>