populate one dropdown based on selection in another dropdown

Community Beginner ,
Oct 15, 2020 Oct 15, 2020

Copy link to clipboard

Copied

123.png

 

Hi All, 

Please refer above snap,

if i choose animals name in dropdown1, and their child names auomate change in dropdown2.

 

Please suggest me, how is possible if code available it may be veryful to understand.

Thanks

TOPICS
Activation billing and install, Bug, Feature request, How to, Import and export, InCopy workflow, Performance, Print, Publish online, Scripting, Server developers, Sync and storage, Type

Views

221

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct Answers

Adobe Community Professional , Oct 15, 2020 Oct 15, 2020
Hi, Try following snippet var dialog = new Window("dialog"); dialog.text = "Dialog"; dialog.preferredSize.width = 400; dialog.orientation = "column"; dialog.alignChildren = ["left", "top"]; dialog.spacing = 10; dialog.margins = 16; var _list_array = ["Animals", "Birds"]; var _list = dialog.add("dropdownlist", undefined, undefined, { name: "_list", items: _list_array }); _list.selection = 0; _list.alignment = ["left", "top"]; _subList_Array = getList(_list.selection.text); var _list1 = dialog.a...

Likes

Translate

Translate
Adobe Community Professional , Oct 15, 2020 Oct 15, 2020
Incorporate my earlier code in your script. var dialog = new Window("dialog"); dialog.text = "Dialog"; dialog.orientation = "column"; dialog.alignChildren = ["center","top"]; dialog.spacing = 10; dialog.margins = 16; // GROUP1 // ====== var group1 = dialog.add("group", undefined, {name: "group1"}); group1.orientation = "row"; group1.alignChildren = ["left","center"]; group1.spacing = 10; group1.margins = 0; var statictext1 = group1.add("statictext", undefined, undefined, {name: "statictext1"})...

Likes

Translate

Translate
Enthusiast ,
Oct 15, 2020 Oct 15, 2020

Copy link to clipboard

Copied

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 15, 2020 Oct 15, 2020

Copy link to clipboard

Copied

Hi Mike,

 

Thanks for your reponse, but i get confuse to use above url,

 

i shared the source code, please do a needfull

 

 

// ======
var dialog = new Window("dialog");
dialog.text = "Dialog";
dialog.orientation = "column";
dialog.alignChildren = ["center","top"];
dialog.spacing = 10;
dialog.margins = 16;

// GROUP1
// ======
var group1 = dialog.add("group", undefined, {name: "group1"});
group1.orientation = "row";
group1.alignChildren = ["left","center"];
group1.spacing = 10;
group1.margins = 0;

var statictext1 = group1.add("statictext", undefined, undefined, {name: "statictext1"});
statictext1.text = "Family Name";

var dropdown1_array = ["Animals","Birds","Vegitables"];
var dropdown1 = group1.add("dropdownlist", undefined, undefined, {name: "dropdown1", items: dropdown1_array});
dropdown1.preferredSize.width = 100;

// GROUP2
// ======
var group2 = dialog.add("group", undefined, {name: "group2"});
group2.orientation = "row";
group2.alignChildren = ["left","center"];
group2.spacing = 10;
group2.margins = 0;

var statictext2 = group2.add("statictext", undefined, undefined, {name: "statictext2"});
statictext2.text = "Child Name";

var dropdown2 = group2.add("dropdownlist", undefined, undefined, {name: "dropdown2"});
dropdown2.selection = 0;
dropdown2.preferredSize.width = 100;

dialog.show();

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Oct 15, 2020 Oct 15, 2020

Copy link to clipboard

Copied

Incorporate my earlier code in your script.

var dialog = new Window("dialog");
dialog.text = "Dialog";
dialog.orientation = "column";
dialog.alignChildren = ["center","top"];
dialog.spacing = 10;
dialog.margins = 16;

// GROUP1
// ======
var group1 = dialog.add("group", undefined, {name: "group1"});
group1.orientation = "row";
group1.alignChildren = ["left","center"];
group1.spacing = 10;
group1.margins = 0;

var statictext1 = group1.add("statictext", undefined, undefined, {name: "statictext1"});
statictext1.text = "Family Name";

var dropdown1_array = ["Animals","Birds","Vegitables"];
var dropdown1 = group1.add("dropdownlist", undefined, undefined, {name: "dropdown1", items: dropdown1_array});
dropdown1.preferredSize.width = 100;

//Start of Updated Code
dropdown1.selection = 0;
var _subList_Array = getList(dropdown1.selection.text);
dropdown1.onChange = function(){
    for (var i = dropdown2.items.length - 1; i >= 0; i--) {
        dropdown2.remove(dropdown2.items[i]);
    }
    var newList = getList(dropdown1.selection.text);
    for (var i = 0; i < newList.length; i++) {
        dropdown2.add('item', newList[i]);
    }
    dropdown2.selection = 0;
}
//End of Updated Code

// GROUP2
// ======
var group2 = dialog.add("group", undefined, {name: "group2"});
group2.orientation = "row";
group2.alignChildren = ["left","center"];
group2.spacing = 10;
group2.margins = 0;

var statictext2 = group2.add("statictext", undefined, undefined, {name: "statictext2"});
statictext2.text = "Child Name";

var dropdown2 = group2.add("dropdownlist", undefined, undefined, {name: "dropdown2",items: _subList_Array}); 
dropdown2.selection = 0;
dropdown2.preferredSize.width = 100;

dialog.show();


//Added getList method
function getList(name) {
    switch (name.toLowerCase()) {
        case 'animals':
            return ['Dog', 'Cat'];

        case 'birds':
            return ['Peacock', 'Sparrow'];

        case 'vegitables':
            return ['Potato', 'Onion']
    }
}

Hope this helps you.

 

Best regards

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Oct 15, 2020 Oct 15, 2020

Copy link to clipboard

Copied

Hi,

Try following snippet

var dialog = new Window("dialog");
dialog.text = "Dialog";
dialog.preferredSize.width = 400;
dialog.orientation = "column";
dialog.alignChildren = ["left", "top"];
dialog.spacing = 10;
dialog.margins = 16;


var _list_array = ["Animals", "Birds"];
var _list = dialog.add("dropdownlist", undefined, undefined, { name: "_list", items: _list_array });
_list.selection = 0;
_list.alignment = ["left", "top"];
_subList_Array = getList(_list.selection.text);
var _list1 = dialog.add("dropdownlist", undefined, undefined, { name: "_list1", items: _subList_Array });
_list1.selection = 0;
_list1.alignment = ["left", "top"];

_list.onChange = function () {
    for (var i = _list1.items.length - 1; i >= 0; i--) {
        _list1.remove(_list1.items[i]);
    }
    var newList = getList(_list.selection.text);
    for (var i = 0; i < newList.length; i++) {
        _list1.add('item', newList[i]);
    }
    _list1.selection = 0;
}

dialog.show();

function getList(name) {
    switch (name.toLowerCase()) {
        case 'animals':
            return ['Dog', 'Cat'];

        case 'birds':
            return ['Peacock', 'Sparrow'];
    }
}
Best regards

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 15, 2020 Oct 15, 2020

Copy link to clipboard

Copied

Hi Charu, Thanks a lot, you lines are so amazing.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Oct 15, 2020 Oct 15, 2020

Copy link to clipboard

Copied

LATEST

You're welcome.

Great! it works for you.

Best regards

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines