Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Removing options in select tag

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

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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

580 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