简体   繁体   中英

Radio button selection creates a dynamic drop down list

I am trying to create a drop down list that is dynamically populated depending on what selection is made in a group of radio buttons. I currently have a group of radio buttons names "Applicability" and the options to select are: People, Procedure, Environment, Capability to deliver, Technical Airworthiness and Operational Airworthiness. Depending on which one is selected, I would like the drop down box to populate with a number of options to select. The code I am working with at the moment is:

var peList = [“Worker Type”, “Injury Type”];
var enList = [“Undefined”];
var prList = ["Facility", "Building", "Plant", "Damage Type"];
var caList = ["To Be Determined"];
var teList = ["Aircraft", "Component"];
var opList = ["Nothing at the moment"];

if (Applicability.rawValue===”People”) {
           DropDownList4.clearItems;
    for (var i = 0; i < peList.length; i++) { 
        DropDownList4.addItem(peList[i]);
}
        } else if (Applicability.rawValue===”Property”) {
           DropDownList4.clearItems;
    for (var i = 0; i < prList.length; i++) { 
        DropDownList4.addItem(prList[i]);
        }
        } else if (Applicability.rawValue===”Environment”) {
           DropDownList4.clearItems;
    for (var i = 0; i < enList.length; i++) { 
        DropDownList4.addItem(enList[i]);
        }
        } else if (Applicability.rawValue===”CapabilityToDeliver”) {
           DropDownList4.clearItems;
    for (var i = 0; i < caList.length; i++) { 
        DropDownList4.addItem(caList[i]);
        }
        } else if (Applicability.rawValue===”TechnicalAirworthiness”) {
           DropDownList4.clearItems;
    for (var i = 0; i < taList.length; i++) { 
        DropDownList4.addItem(taList[i]);
        }
        } else if (Applicability.rawValue===”OperationalAirworthiness”) {
           DropDownList4.clearItems;
    for (var i = 0; i < opList.length; i++) { 
        DropDownList4.addItem(opList[i]);}

Can you please assist by showing me where I might be going wrong? Thank you

clearitems is a method and should be called as DropDownList4.clearItems(); Note the parenthesis here that are missing in your code. Also, make the code much more maintainable by using switch. For example:

var a,al,ax; // array, array length, array index
switch(Applicability.rawValue){
case 'People': a=['Worker Type', 'Injury Type'];break;
case 'Property': a=['Facility', 'Building', 'Plant', 'Damage Type'];break;
case 'Environment': a=['Undefined'];break;
case 'CapabilityToDeliver': a=['To Be Determined'];break;
case 'TechnicalAirworthiness': a=['Aircraft', 'Component'];break;
case 'OperationalAirworthiness': a=['Nothing at the moment'];break;
default:
 // put your exception handling code here.
}
DropDownList4.clearItems();
for(ax=0,al=a.length;ax<al;ax++){ 
 DropDownList4.addItem(a[ax]);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM