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

Drop Down menu if condition

Participant ,
Jun 21, 2021 Jun 21, 2021

I want to Select Black And its show Black in Dropdown menu, when i click dropdown menu its show red only---

 

Step 1:- I Select Black in Drop Down Menu

Step 2:- Alert:- You have selected Black

 

My If condition is not satisfied, How to put right condition of if 

 

var dlgMain = new Window("dialog","CCCCCCC", undefined, { closeButton:true} )
dlgMain.marginLeft = 15;
dlgMain.center();
dlgMain.orientation = "row";

var dropdown7_array = ["Black","Red","White","Blue","Green"];
var dropdown7 = dlgMain.add("dropdownlist", undefined, undefined, {name: "dropdown7", items: dropdown7_array});
dropdown7.selection = 0;

dlgMain.show();

if(dropdown7.selection==dropdown7.items);
{
alert("red");
}

TOPICS
Actions and scripting
3.3K
Translate
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 1 Correct answer

LEGEND , Jun 21, 2021 Jun 21, 2021

I extended my code of .text, so now you can use conditions to check chosen color name.

Translate
Adobe
LEGEND ,
Jun 21, 2021 Jun 21, 2021

Over dlgMain.show(); put this code line:

 

dropdown7.onChange = function() {alert(this.selection)}

 

Ps. you may also remove your code from beyond dlgMain.show();

Translate
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
Participant ,
Jun 21, 2021 Jun 21, 2021

Thanku so much It Worked...

But I Select Black , It's show me you have selected Black

 


var dlgMain = new Window("dialog","CCCCCCC", undefined, { closeButton:true} )
dlgMain.marginLeft = 15;
dlgMain.center();
dlgMain.orientation = "row";

var dropdown7_array = ["Black","Red","White","Blue","Green"];
var dropdown7 = dlgMain.add("dropdownlist", undefined, undefined, {name: "dropdown7", items: dropdown7_array});
dropdown7.selection = 0;

dropdown7.onChange=function()
{
if(this.selection=="Black")
{
alert("You have Selected Black");
}

if(this.selection=="Red")
{
alert("You have Selected Red");
}
}
dlgMain.show();
/* if(dropdown7.selection

Translate
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
LEGEND ,
Jun 21, 2021 Jun 21, 2021

Step back to your original code and instead of code line from my previous post use this one:

 

dropdown7.onChange=function(){alert('You\'ve Selected '+this.selection.text)}

 

Translate
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
Participant ,
Jun 21, 2021 Jun 21, 2021

You code is right but my question is not understand you have !

 

Step 1:- I Select Black :- 

var strokeColorB = new RGBColor();
strokeColorB.hexValue = '000000';

 

Step 2:- I Select White Again:-

var strokeColorW = new RGBColor();
strokeColorW.hexValue = 'ffffff';

 

I want to condition of if in dropdown menu

Translate
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
LEGEND ,
Jun 21, 2021 Jun 21, 2021

I extended my code of .text, so now you can use conditions to check chosen color name.

Translate
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
Participant ,
Jun 21, 2021 Jun 21, 2021

Yes @Kukurykus  Right Answar @!

Thanku so much @Kukurykus 

Translate
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
LEGEND ,
Jun 21, 2021 Jun 21, 2021

Alternatively you can play with:

 

sc = new SolidColor()
clrs = {0: '000000', 1: 'ff0000', 2: 'ffffff', 3: '0000ff', 4: '00ff00'}
dropdown7.onChange = function() {sc.hexValue = clrs[this.selection.index]}

 

Translate
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
Participant ,
Jun 21, 2021 Jun 21, 2021

Wow @Kukurykus  You are great for knowledge !

Translate
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
Participant ,
Jul 17, 2021 Jul 17, 2021

Can you modify the code :- 

                  var st = new RGBColor()
            st.hexValue = '000000';
clrs = {0: '000000', 1: 'ff0000', 2: '00ff30', 3: '0024ff', 4:'ff00f0',5:'fff600'}
dropdown4.onChange = function() 
{st.hexValue = clrs[this.selection.index]}

Getting a error !

Translate
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
People's Champ ,
Jul 17, 2021 Jul 17, 2021
What's the error?
Can we see all the code?
 
 
 
Translate
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
Participant ,
Jul 17, 2021 Jul 17, 2021

Getting a Error :- "Required Value is missing"

TextLayer("Photoshop");


                  var st = new RGBColor()
            st.hexValue = '000000';
clrs = {0: '000000', 1: 'ff0000', 2: '00ff30', 3: '0024ff', 4:'ff00f0',5:'fff600'}
dropdown4.onChange = function() 
{st.hexValue = clrs[this.selection.index]}
        

function TextLayer(text) {

        var layers = app.activeDocument.artLayers;
        var layer = layers.add();
        layer.kind = LayerKind.TEXT;
        var textItem = layer.textItem;
        //textItem.kind = TextType.PARAGRAPHTEXT;
        textItem.size = 18;
        //textItem.position = [20, 500];
        myColor = new SolidColor
        myColor.rgb.red = 255
        myColor.rgb.green = 0
        myColor.rgb.blue = 0
        textItem.color=st;
        textItem.contents = text;
       // textItem.width = new UnitValue(" 100 pixels");
        //textItem.height = new UnitValue("30 pixels");
}
Translate
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
People's Champ ,
Jul 17, 2021 Jul 17, 2021
This is not all the code. For example, where is dropdown4 specified?
 
Also textItem.color is SolidColor. You are trying to set it to the value of the "st" variable, which is an RGBColor object.
 
 
 
Translate
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
Participant ,
Jul 17, 2021 Jul 17, 2021

Here is full code

/*
Code for Import https://scriptui.joonas.me — (Triple click to select): 
{"activeId":2,"items":{"item-0":{"id":0,"type":"Dialog","parentId":false,"style":{"enabled":true,"varName":null,"windowType":"Dialog","creationProps":{"su1PanelCoordinates":false,"maximizeButton":false,"minimizeButton":false,"independent":false,"closeButton":true,"borderless":false,"resizeable":false},"text":"NNNNNN","preferredSize":[0,0],"margins":16,"orientation":"column","spacing":10,"alignChildren":["center","top"]}},"item-2":{"id":2,"type":"DropDownList","parentId":0,"style":{"enabled":true,"varName":null,"text":"DropDownList","listItems":"Black,Pink,Blue,Red","preferredSize":[0,0],"alignment":null,"selection":0,"helpTip":null}}},"order":[0,2],"settings":{"importJSON":true,"indentSize":false,"cepExport":false,"includeCSSJS":true,"showDialog":true,"functionWrapper":false,"afterEffectsDockable":false,"itemReferenceList":"None"}}
*/ 

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

var dropdown1_array = ["Black","Pink","Blue","Red"]; 
var dropdown4 = dialog.add("dropdownlist", undefined, undefined, {name: "dropdown4", items: dropdown1_array}); 
    dropdown4.selection = 0; 

dialog.show();




TextLayer("Photoshop");


                  var st = new SolidColor
            st.hexValue = '000000';
clrs = {0: '000000', 1: 'ff0000', 2: '00ff30', 3: '0024ff', 4:'ff00f0',5:'fff600'}
dropdown4.onChange = function() 
{st.hexValue = clrs[this.selection.index]}
        

function TextLayer(text) {

        var layers = app.activeDocument.artLayers;
        var layer = layers.add();
        layer.kind = LayerKind.TEXT;
        var textItem = layer.textItem;
        //textItem.kind = TextType.PARAGRAPHTEXT;
        textItem.size = 18;
        //textItem.position = [20, 500];
        textItem.color=st;
        textItem.contents = text;
       // textItem.width = new UnitValue(" 100 pixels");
        //textItem.height = new UnitValue("30 pixels");
}

 I want to change the Text Color in Dropdown menu

Translate
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
People's Champ ,
Jul 17, 2021 Jul 17, 2021

The st variable must be declared before calling dialog.show().

You also need to use st.rgb, not just st

 

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

var dropdown1_array = ["Black","Pink","Blue","Red"]; 
var dropdown4 = dialog.add("dropdownlist", undefined, undefined, {name: "dropdown4", items: dropdown1_array}); 
    dropdown4.selection = 0; 

var st = new SolidColor
st.rgb.hexValue = '000000';
clrs = {0: '000000', 1: 'ff0000', 2: '00ff30', 3: '0024ff', 4:'ff00f0',5:'fff600'}
dropdown4.onChange = function() 
{st.rgb.hexValue = clrs[this.selection.index]}
        

dialog.show();

TextLayer("Photoshop");

function TextLayer(text) {

        var layers = app.activeDocument.artLayers;
        var layer = layers.add();
        layer.kind = LayerKind.TEXT;
        var textItem = layer.textItem;
        //textItem.kind = TextType.PARAGRAPHTEXT;
        textItem.size = 18;
        //textItem.position = [20, 500];
        textItem.color=st;
        textItem.contents = text;
       // textItem.width = new UnitValue(" 100 pixels");
        //textItem.height = new UnitValue("30 pixels");
}
Translate
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
Participant ,
Jul 17, 2021 Jul 17, 2021

Yes i have used st.rgb But getting "internal error"

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

var dropdown4_array = ["Black","Pink","Blue","Red"]; 
var dropdown4 = dialog.add("dropdownlist", undefined, undefined, {name: "dropdown4", items: dropdown4_array}); 
    dropdown4.selection = 0; 

var st = new SolidColor
st.rgb.hexValue = '000000';
clrs = {0: '000000', 1: 'ff0000', 2: '00ff30', 3: '0024ff', 4:'ff00f0',5:'fff600'}
dropdown4.onChange = function() 
{st.rgb.hexValue = clrs[this.selection.index]}
        

dialog.show();

TextLayer("Photoshop");

function TextLayer(text) {

        var layers = app.activeDocument.artLayers;
        var layer = layers.add();
        layer.kind = LayerKind.TEXT;
        var textItem = layer.textItem;
        //textItem.kind = TextType.PARAGRAPHTEXT;
        textItem.size = 18;
        //textItem.position = [20, 500];
        textItem.color=st.rgb;
        textItem.contents = text;
       // textItem.width = new UnitValue(" 100 pixels");
        //textItem.height = new UnitValue("30 pixels");
}
Translate
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
People's Champ ,
Jul 17, 2021 Jul 17, 2021
I gave a working code above. Compare it to yours.
Translate
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
Participant ,
Jul 17, 2021 Jul 17, 2021

I have compared with your code All are right but getting a error, Please check it what is problem ?

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

var dropdown4_array = ["Black","Pink","Blue","Red"]; 
var dropdown4 = dialog.add("dropdownlist", undefined, undefined, {name: "dropdown4", items: dropdown4_array}); 
    dropdown4.selection = 0; 

var st = new SolidColor()
st.hexValue = '000000';
clrs = {0: '000000', 1: 'ff0000', 2: '00ff30', 3: '0024ff', 4:'ff00f0',5:'fff600'}
dropdown4.onChange = function() 
{st.hexValue = clrs[this.selection.index]}
        

dialog.show();

TextLayer("Photoshop");

function TextLayer(text) {

        var layers = app.activeDocument.artLayers;
        var layer = layers.add();
        layer.kind = LayerKind.TEXT;
        var textItem = layer.textItem;
        //textItem.kind = TextType.PARAGRAPHTEXT;
        textItem.size = 18;
        //textItem.position = [20, 500];
        textItem.color=st.rgb;
        textItem.contents = text;
       // textItem.width = new UnitValue(" 100 pixels");
        //textItem.height = new UnitValue("30 pixels");
}

 

 

 

 

 

 

 

 

 

 

 

;-

Translate
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
People's Champ ,
Jul 17, 2021 Jul 17, 2021
quote

I have compared with your code All are right but getting a error, Please check it what is problem ?


By @MXKS

 

Find three differences

Translate
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
Participant ,
Jul 17, 2021 Jul 17, 2021

Yes, Correct it but same issue 

Translate
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
People's Champ ,
Jul 17, 2021 Jul 17, 2021
Does my code work for you without errors? Show your code again, which gives the error.
 
 
 
Translate
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
Participant ,
Jul 17, 2021 Jul 17, 2021

Check it ,I'm tired to resolve the error !

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

var dropdown4_array = ["Black","Pink","Blue","Red"]; 
var dropdown4 = dialog.add("dropdownlist", undefined, undefined, {name: "dropdown4", items: dropdown4_array}); 
    dropdown4.selection = 0; 

var st = new SolidColor()
st.hexValue = '000000';
clrs = {0: '000000', 1: 'ff0000', 2: '00ff30', 3: '0024ff', 4:'ff00f0',5:'fff600'}
dropdown4.onChange = function() 
{st.hexValue = clrs[this.selection.index]}
        

dialog.show();

TextLayer("Photoshop");

function TextLayer(text) {

        var layers = app.activeDocument.artLayers;
        var layer = layers.add();
        layer.kind = LayerKind.TEXT;
        var textItem = layer.textItem;
        //textItem.kind = TextType.PARAGRAPHTEXT;
        textItem.size = 18;
        //textItem.position = [20, 500];
        textItem.color=st.rgb;
        textItem.contents = text;
       // textItem.width = new UnitValue(" 100 pixels");
        //textItem.height = new UnitValue("30 pixels");
}
Translate
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
People's Champ ,
Jul 17, 2021 Jul 17, 2021

This is not my code. My code is here Drop Down menu if condition

 

 

P.S. I'm sick of

Translate
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
Participant ,
Jul 17, 2021 Jul 17, 2021

Ok @r-bin  Thanku so much , Code is worked fine

Translate
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
LEGEND ,
Jul 17, 2021 Jul 17, 2021
LATEST

To avoid spamming next time link a post with a code you once published in exact same shape.

Translate
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