Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8910989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:49:54+00:00 2026-06-15T03:49:54+00:00

This is an additional question regarding sub categories. The current problem is that when

  • 0

This is an additional question regarding sub categories. The current problem is that when I change options the function to clear the OS list is not working and it conntinues to grow as changes are made. I tried adding the remove function everywhere and it still does not work. To recreate the issue, select internal for network and then look at the OS list. Select physical for resource and then look at the OS list. I have a function called removeAllOptions in the list.js file that is not clearing the OS selections when the resource is changed. It does work when the network is changed. Any ideas are much appreciated.

Thanks,
Ray

JS Fiddle

index.php

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

    <head>
    <script language="javascript" src="list.js"></script>
    </head>
    <head>
   <script language="javascript" src="list.js"></script>
</head>
<div class="left_box" />
<body onload="fillCategory();">
   <div id="formWrapper" />
   <FORM name="drop_list" action="availability.php" method="POST" />
   <fieldset>
      <label>Network</label>
      <SELECT class="formSelect" NAME="build" onChange="selectResource();">
         <Option value="">Select Internal or Firewall</option>
      </SELECT>
      <br />
      <br />
      <label>Resource</label>
      <SELECT class="formSelect" id="resource" NAME="resource" 
          onChange="selectOS(this);">
         <Option value="">Resource</option>
      </SELECT>
      <br />
      <br />
      <label>OS</label>
      <SELECT class="formSelect" id="OS" NAME="OS">
         <Option value="">OS</option>
      </SELECT>
      <br />
      <br />
   </fieldset>

list.js

function fillCategory(){ 
 // this function is used to fill the category list on load
addOption(document.drop_list.build, "Internal", "Internal", "");
addOption(document.drop_list.build, "Internal Cluster", "Internal Cluster", "");
addOption(document.drop_list.build, "Firewall", "Firewall", "");
addOption(document.drop_list.build, "Firewall Cluster", "Firewall Cluster", "");
}

function selectResource(){
// ON selection of category this function will work
removeAllOptions(document.drop_list.resource);
removeAllOptions(document.drop_list.OS);

if((document.drop_list.build.value == 'Internal')||(document.drop_list.build.value == 'Firewall')){
addOption(document.drop_list.resource,"Virtual", "Virtual","");
addOption(document.drop_list.resource,"Physical", "Physical","");
}

if((document.drop_list.build.value == 'Internal Cluster') || (document.drop_list.build.value     == 'Firewall Cluster')) {
addOption(document.drop_list.resource,"Physical", "Physical");
}
    selectOS();
}
function selectOS(el){

if(document.drop_list.build.value == 'Internal') {
addOption(document.drop_list.OS,"AIX 6.1", "AIX 6.1");
addOption(document.drop_list.OS,"Linux 5.0 (64-bit)", "Linux 5.0 (64-bit)");
addOption(document.drop_list.OS,"Linux 6.0 (64-bit)", "Linux 6.0 (64-bit)");
addOption(document.drop_list.OS,"Solaris 10", "Solaris 10");
addOption(document.drop_list.OS,"Windows 2008 (64-bit) Standard", "Windows 2008 (64-bit) Standard");
addOption(document.drop_list.OS,"Windows 2008 (64-bit) Enterprise", "Windows 2008 (64-bit)   Enterprise");
addOption(document.drop_list.OS,"Windows 2008 R2 (64-bit) Standard", "Windows 2008 R2 (64-bit)  Standard");
addOption(document.drop_list.OS,"Windows 2008 R2 (64-bit) Enterprise", "Windows 2008 R2 (64-bit) Enterprise");
addOption(document.drop_list.OS,"Special", "Special");
}

if((document.drop_list.build.value == 'Internal Cluster') ||(document.drop_list.build.value == 'Firewall Cluster')){
addOption(document.drop_list.OS,"AIX 6.1", "AIX 6.1");
addOption(document.drop_list.OS,"Linux 5.0 (64-bit)", "Linux 5.0 (64-bit)");
addOption(document.drop_list.OS,"Linux 6.0 (64-bit)", "Linux 6.0 (64-bit)");
addOption(document.drop_list.OS,"Solaris 10", "Solaris 10");
addOption(document.drop_list.OS,"Windows 2008 (64-bit) Enterprise", "Windows 2008 (64-bit) Enterprise");
addOption(document.drop_list.OS,"Windows 2008 R2 (64-bit) Enterprise", "Windows 2008 R2 (64-bit) Enterprise");
}

if((document.drop_list.build.value == 'Firewall') && (document.drop_list.resource.value == 'Virtual')) {
addOption(document.drop_list.OS,"Linux 5.0 (64-bit)", "Linux 5.0 (64-bit)");
addOption(document.drop_list.OS,"Linux 6.0 (64-bit)", "Linux 6.0 (64-bit)");
addOption(document.drop_list.OS,"Windows 2008 (64-bit) Enterprise", "Windows 2008 (64-bit) Enterprise");
addOption(document.drop_list.OS,"Windows 2008 R2 (64-bit) Enterprise", "Windows 2008 R2 (64-bit) Enterprise");
}

if((document.drop_list.build.value == 'Firewall') && (document.drop_list.resource.value == 'Physical')) {
addOption(document.drop_list.OS,"AIX 6.1", "AIX 6.1");
addOption(document.drop_list.OS,"Linux 5.0 (64-bit)", "Linux 5.0 (64-bit)");
addOption(document.drop_list.OS,"Linux 6.0 (64-bit)", "Linux 6.0 (64-bit)");
addOption(document.drop_list.OS,"Solaris 10", "Solaris 10");
addOption(document.drop_list.OS,"Windows 2008 (64-bit) Enterprise", "Windows 2008 (64-bit) Enterprise");
addOption(document.drop_list.OS,"Windows 2008 R2 (64-bit) Enterprise", "Windows 2008 R2 (64-bit) Enterprise");
}

} 

function removeAllOptions(selectbox)
{
    var i;
    for(i=selectbox.options.length-1;i>=0;i--)
{
    //selectbox.options.remove(i);
    selectbox.remove(i);
}
} 


function addOption(selectbox, value, text )
{
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;

selectbox.options.add(optn);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:49:55+00:00Added an answer on June 15, 2026 at 3:49 am

    For a Quick fix you can call the removeAllOptions() function whenever you call the function.

    But you have too much of repeated code , and trying to access a DOM every single time you call the select box.

    Better to cache them.

    Code

    var networkList = '';
    var resourceList = '';
    var osList = '';
    
    function fillCategory() {
        // this function is used to fill the category list on load
        networkList = document.drop_list.build;
        resourceList = document.drop_list.resource;
        osList = document.drop_list.OS;
        var catOptions = ["Internal", "Internal Cluster"
                          , "Firewall", "Firewall Cluster"];
        addOptions(networkList, catOptions);
    }
    
    function selectResource() {
        // ON selection of category this function will work
        removeAllOptions(resourceList);
        removeAllOptions(osList);
        var networkValue = networkList.value;
    
        if ((networkValue == 'Internal') || (networkValue == 'Firewall')) {
            addOptions(resourceList, ["Virtual", "Physical"]);
        }
        else if ((networkValue == 'Internal Cluster') 
                   || (networkValue == 'Firewall Cluster')) {
            addOptions(resourceList, ["Physical"]);
        }
        selectOS();
    }
    
    function selectOS(el) {
        var networkValue = networkList.value;
        var resourceValue = resourceList.value;
    
        var internalOS = ["AIX 6.1","Linux 5.0 (64-bit)","Linux 6.0 (64-bit)"
                          ,"Solaris 10","Windows 2008 (64-bit) Standard"
                          ,"Windows 2008 (64-bit) Enterprise"
                          , "Windows 2008 R2 (64-bit) Standard" 
                          ,"Windows 2008 R2 (64-bit) Enterprise"
                          , "Special"];
        var clusterOS = ["AIX 6.1","Linux 5.0 (64-bit)","Linux 6.0 (64-bit)",
                         "Solaris 10","Windows 2008 (64-bit) Enterprise"
                         ,"Windows 2008 R2 (64-bit) Enterprise" ];
    
        var firewallOS = ["Linux 5.0 (64-bit)","Linux 6.0 (64-bit)"
                           ,"Windows 2008 (64-bit) Enterprise"
                          ,"Windows 2008 R2 (64-bit) Enterprise" ];
    
        removeAllOptions(osList); // Clear your OS list here
        if (networkValue == 'Internal') {
            addOptions(osList , internalOS);
        }
        else if ((networkValue == 'Internal Cluster') 
                  || (networkValue == 'Firewall Cluster')) {
            addOptions(osList , clusterOS);
        }
        else if ((networkValue == 'Firewall') && (resourceValue == 'Virtual')) {
           addOptions(osList , firewallOS);
        }
        else if ((networkValue == 'Firewall') && (resourceValue == 'Physical')) {
            addOptions(osList , clusterOS);
        }
    
    }
    
    function removeAllOptions(selectbox) {
        var i;
        for (i = selectbox.options.length - 1; i >= 0; i--) {
            selectbox.remove(i);
        }
    }
    
    function addOptions(selectbox, arr) {
        // use an array to populate Select Options
        for (var i = 0; i < arr.length; i++) {
            var optn = document.createElement("OPTION");
            optn.text = arr[i];
            optn.value = arr[i];
            selectbox.options.add(optn);
        }
    }​
    

    This can be lot more optimized.. Also you can use jQuery for such purposes. Better to move the inline javascript to the script itself.

    Working Fiddle

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I bumped into an additional question that I needed in regards to this: Using
Referencing Is Facebook an OpenID provider? here. This is kind of an additional question
I was looking at this question: Add additional data to a Highcharts series for
This is just a general question regarding the debate between self-signed certificates and CA
One question regarding whether the following code should yield a compiler warning or not
This question is regarding dynamic linking of libraries and usage of dynamic linking of
This post follows a previous question regarding the restructuring of a matrix: re-formatting a
I have a question regarding the two additional columns (timeCreated, timeLastUpdated) for each record
I have a question regarding this code. I'm a beginner and enjoy learning C#.
This is regarding the question: Turn off display in iPhone OS (iOS) As alternative

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.