• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How do make something change when menu item is selected?

New Here ,
Sep 27, 2020 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

Views

306

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
Advocate ,
Sep 27, 2020 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();
};

Votes

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
New Here ,
Sep 27, 2020 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? 

Votes

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

Votes

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
New Here ,
Sep 28, 2020 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? 

Votes

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

Votes

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
New Here ,
Sep 28, 2020 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? 

Votes

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
Valorous Hero ,
Sep 28, 2020 Sep 28, 2020

Copy link to clipboard

Copied

LATEST

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

Votes

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