Solved

Removing options in select tag

Posted on 2004-09-25
3
1,268 Views
Last Modified: 2008-01-09
   
   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
0
Comment
Question by:Manish
  • 2
3 Comments
 
LVL 25

Expert Comment

by:devic
ID: 12150276
try this:
==================
function remAllOpt()
{
    while(document.frmApplication.department.length>0)
    document.frmApplication.department.options[0]=null;
}
0
 
LVL 25

Accepted Solution

by:
devic earned 125 total points
ID: 12150282
or this:
================
function remAllOpt()
{
    document.frmApplication.department.length=null;
}
0
 
LVL 11

Author Comment

by:Manish
ID: 12150455
Thanks devic .....grt..!
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now