javascript - Delete Options from two dropdowns -
so have 2 dropdowns,like this:
<select id="listbox" name="listbox" multiple="multiple"> <option> value </option> <option> value b </option> <option> value c </option> </select> <select id="listbox2" name="listbox2" multiple="multiple"> <option> value 1 </option> <option> value 2 </option> <option> value 3 </option> </select> so when user selects value a , click on "delete" button,it should delete value a , corresponding position value 1 , vice-versa.
i have javascript code doesn't work properly,here is:
function removeoption() { var x = new array(); x[0] = document.getelementbyid("listbox"); x[1] = document.getelementbyid("listbox2"); x[0].remove(x[0].selectedindex); x[1].remove(x[1].selectedindex); } could guys help me out????
you can utilize function
function removeselected(d1,d2){ element=document.getelementbyid(d1); element1=document.getelementbyid(d2); var value= new array(); var value1= new array(); while(element.selectedindex != -1) { var t=element.selectedindex; value.push(element.options[t]); value1.push(element1.options[t]); element.options[t].selected = false; } for(var = 0; < value.length; i++) { element.removechild(value[i]); element1.removechild(value1[i]); }; } for phone call utilize this
function remover(){ removeselected('listbox','listbox2'); removeselected('listbox2','listbox'); } when phone call remove selected dropdowns , similar index other dropdowns
javascript jquery select listbox
No comments:
Post a Comment