Remove selected items from select box


/ Published in: JavaScript

This will remove the items in a select box/list box that have been selected.


Copy this code and paste it in your HTML
  1. function remove_selected_items(listid){
  2. var list = document.getElementById(listid);
  3. var items = list.options.length;
  4.  
  5. for(var i = items-1; i >= 0; i--) {
  6. if(list.options[i].selected == true){
  7. list.remove(i);
  8. }
  9. }
  10. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.