Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Removing options in select tag

Posted on 2004-09-25
3
Medium Priority
?
1,278 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 500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…
Suggested Courses

971 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