Solved

Removing options in select tag

Posted on 2004-09-25
3
1,274 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

734 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