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; 
2
  • have a look at this Removing an item from a select box Commented Mar 6, 2013 at 8:33
  • may i know why the question is down voted? Commented Mar 6, 2013 at 9:01

2 Answers 2

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); } } 
Sign up to request clarification or add additional context in comments.

Comments

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 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.