1
  • On click of create button, am creating a combo box option dynamically.
  • My need is, on click of delete button, i have to delete the dynamically created option.

Combo box code:

<select id="connectionname" class="connectionname" onchange="display();" style="width:150px; height:23px;">
     <option>---Select---</option>
</select>

javascript to create/add options dynamically:

var NAME =dijit.byId("conname").getValue();
    var newValue = document.getElementById("connectionname").appendChild(document.createElement('option'));
    newValue.text = NAME;
    document.getElementById("connectionname").value = newValue.text;
Ravindra Gullapalli
  • 9,049
  • 3
  • 48
  • 70
Rachel
  • 1,131
  • 11
  • 26
  • 43

2 Answers2

2
var NAME =dijit.byId("conname").getValue();
var select=document.getElementById('connectionname');

for (i=0;i<select.length;  i++) {
   if (select.options[i].text==NAME) {
     select.remove(i);
   }
}
Ravindra Gullapalli
  • 9,049
  • 3
  • 48
  • 70
1

You can use the removeChild method to remove dynamically added children

var elem =  document.getElementById("connectionname");
elem.removeChild(elem.childNodes[i]); // where i is index of child added last
U.P
  • 7,357
  • 7
  • 39
  • 61