jeudi 8 octobre 2015

Dynamic checkbox list in javascript - not working

I'm trying to create a list of checkboxes when a certain element is selected from the dropdown list. However, in the following code I am getting only the last element in the checkbox list. That is, at the output, there aren't 3 checkboxes (length of my array) but there is only one - only with the last element in the array.

What am I doing wrong?

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>


    <script>
     function chooseTable(db) {


 if(db=="hr.employee"){

var div = document.getElementById("table"); 

var ids = ["id","name", "write_uid"];

var main = document.getElementById('main1');

var parentElement = document.getElementById('ids');

for(var count in ids)
{
    var newCheckBox = document.createElement('input');
    newCheckBox.type = 'checkbox';
    newCheckBox.id = 'id' + count; // need unique Ids!
    parentElement.innerHTML = ids[count];
    newCheckBox.value = ids[count];
    parentElement.appendChild(newCheckBox);

}

 }
 }


 </script>
  <center>
    <bold>
    <h2>
    Make Query
    </h2>
    </bold>

<div id="main1">
<div>

Choose database:<br/>

<select id="table" name="table" onchange="chooseTable(this.value)">

     <option name="choice" value=""></option>
    <option name="choice1" value="hr.employee">Employees</option>
    <option name="choice2" value="account.account">Accounts</option>
  </select>
</div>  

<div id="ids">

</div>
</div>

</center>

  </body>
</html>




Aucun commentaire:

Enregistrer un commentaire