faqts : Computers : Programming : Languages : JavaScript : Forms : SELECT

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

32 of 44 people (73%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

how do I dynamically remove selected option(s) from a selectbox, onClick of a button?

Feb 21st, 2005 18:57
aditya raj, Alessio Bellisomi, Danny Sementilli, Aditya Raj - http://www.adityaraj.co.nr


Try this little function:
function RemoveOptions() {
  field=document.forms[0].SelectBox   //Your selectbox
  for( i=field.length-1; i>=0; i--) {	
    if(field.options[i].selected) {
      for(j=i;j<field.length-1;j++) {
        field.options[j].text=field.options[j+1].text
      }
    field.length--	
    }
  }
}
Bye