Removing options in select tag

   
   I have this code in my  javascript ...this is part of tht..  
     
  //this I used to remove options ..
  var totalopts = document.frmApplication.department.length;
                  alert("total to remove "+totalopts);
           //code for removing all the early options
        for(i=0;i<totalopts;i++)
          {
            document.frmApplication.department.options[i]=null;
            document.frmApplication.department.options.remove(i);
            
          }
            
           var opt = new Option("<--Select Department-- >","0");
            document.frmApplication.department.options.add(opt,0);
          
      //this is for adding new options    
          
                     var j=1;      
                              for(i=0;i<10;i++)
                              {       
            if(officeId==currentOffice){
                        var opt = new Option(DEPT[i],DEPTID[i]);
                                         document.frmApplication.department.options.add(opt,j);      
                                         j=j+1;
                                                 }
                                    }
                                    
            But next time I m calling this function ,
                  options are not going to remove ...
                  First time it is removing as there is no options in it ,,
                  
            Plz help me..
             karan
LVL 11
ManishLeadAsked:
Who is Participating?
 
devicConnect With a Mentor Commented:
or this:
================
function remAllOpt()
{
    document.frmApplication.department.length=null;
}
0
 
devicCommented:
try this:
==================
function remAllOpt()
{
    while(document.frmApplication.department.length>0)
    document.frmApplication.department.options[0]=null;
}
0
 
ManishLeadAuthor Commented:
Thanks devic .....grt..!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.