In a HTML form I have a check box like-
<select class="text" name="department" id="department">
<option value="">Select department</option>
<option value="a">A</option>
<option value="b">B</option>
<option value="c">C</option>
</select>
Now, I wish to give user capability to add or delete departments in the list. He/She may add branched D and E or may delete branch B.
I wrote a Javascript function to list all the branch names as checkboxes to choose the elements to delete-
function deletefield() {
var container = document.getElementById('drop_down');
container.innerHTML="";
for(i=0; i<passed_array.length; i++) {
var check = document.createElement("INPUT");
var br = document.createElement("BR");
check.setAttribute("type","checkbox");
check.setAttribute("value",passed_array[i]);
var label = document.createElement('label');
label.htmlFor = "id";
label.appendChild(document.createTextNode(passed_array[i]));
container.appendChild(check);
container.appendChild(label);
container.appendChild(br);
}
}
But I have no idea how to proceed it forward to delete the selected branches.
On surfing Internet I came across this code
function remove(id) {
return (elem=document.getElementById(id)).parentNode.removeChild(elem);
}
I don't know if it can help with dropdown or not. Could someone help me decide which is the better approach and how should I proceed with it?