Highlighted

How do make something change when menu item is selected?

New Here ,
Sep 27, 2020

Copy link to clipboard

Copied

For a simple drop-down menu in javascript, what function do I need to add to make another parameter change when a user selects a specific menu option? Does onClick work? Like let's say I wanted to make a new layer appear when I picked option 2. 

 

var newPanel = new Window("dialog","name",undefined);

var dropList = newPanel.add("dropdownlist",undefined,["Opt1","Opt2","Opt3"]);
dropList.selection = 0;


if (newPanel != null && newPanel instanceof Window){
newPanel.center();
newPanel.show();
}

 

TOPICS
Actions and scripting, How to

Views

169

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

How do make something change when menu item is selected?

New Here ,
Sep 27, 2020

Copy link to clipboard

Copied

For a simple drop-down menu in javascript, what function do I need to add to make another parameter change when a user selects a specific menu option? Does onClick work? Like let's say I wanted to make a new layer appear when I picked option 2. 

 

var newPanel = new Window("dialog","name",undefined);

var dropList = newPanel.add("dropdownlist",undefined,["Opt1","Opt2","Opt3"]);
dropList.selection = 0;


if (newPanel != null && newPanel instanceof Window){
newPanel.center();
newPanel.show();
}

 

TOPICS
Actions and scripting, How to

Views

170

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
Sep 27, 2020 0
Advocate ,
Sep 27, 2020

Copy link to clipboard

Copied

Not my prefered solution...

#target photoshop

var newPanel = new Window("dialog","name",undefined);
var dropList = newPanel.add("dropdownlist",undefined,["Opt1","Opt2","Opt3"]);

dropList.onChange = function(){  
        newPanel.close()  
        switch(parseInt(dropList.selection)){  
                case 0:     
                //place your code here     
                alert("Opt1");     
                break;     
            case 1:     
                //place your code here     
                alert("Opt2");   
                break;     
            case 2:     
                //place your code here     
                alert("Opt3");     
                break;   
            }  
        }  

if (newPanel != null && newPanel instanceof Window){
newPanel.center();
newPanel.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
Reply
Loading...
Sep 27, 2020 0
New Here ,
Sep 27, 2020

Copy link to clipboard

Copied

You really need onChange? Shouldn't there be a modifier function specific to dropdowns like onSwitch or something like that? Also why do you need alerts? Why would buttons have onClick but dropdowns have nothing? 

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
Reply
Loading...
Sep 27, 2020 0
Enthusiast ,
Sep 27, 2020

Copy link to clipboard

Copied

What prevents you from reading the official documentation in which all this is written?

https://www.adobe.com/content/dam/acom/en/devnet/Images/JavaScript-Tools-Guide-CC.pdf

2020-09-28_09-10-16.png

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
Reply
Loading...
Sep 27, 2020 1
New Here ,
Sep 28, 2020

Copy link to clipboard

Copied

How about the fact that there's several different subtly labeled "official" documentations with drastically different information and that they are all badly written and difficult to find anything in? 

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
Reply
Loading...
Sep 28, 2020 0
Advocate ,
Sep 28, 2020

Copy link to clipboard

Copied

[quote]Also why do you need alerts?[/quote]

They are not necessary. They only confirm visually whether "onchange" works.

 

Replace them with your own code...

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
Reply
Loading...
Sep 28, 2020 0
New Here ,
Sep 28, 2020

Copy link to clipboard

Copied

Something else doesn't quite make sense. If all you need is onChange, why is there also this "switch" function in the proposed script? 

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
Reply
Loading...
Sep 28, 2020 0
r-bin LATEST
Adobe Community Professional ,
Sep 28, 2020

Copy link to clipboard

Copied

d0 b4 d0 b5 d0 b1 d0 b8 d0 bb d1 8b 2c 20 d0 b1 d0 bb d1 8f d0 b4 d1 8c

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
Reply
Loading...
Sep 28, 2020 1