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

DropDownList value selected by default?

Participant ,
Nov 20, 2014 Nov 20, 2014

Copy link to clipboard

Copied

Hi there,

I've got the following DropDownList, but it gets rendered with no options selected. How can I make ''one" the default option for this element?

var w, layout;

layout = "dialog {  \

    dropdown: DropDownList { \

        size: [100,20] \

        properties: { \

            items: ['one','two','three'] \

        } \

    } \

}";

w = new Window(layout);

w.show();

Thanks

TOPICS
Actions and scripting

Views

4.5K

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 1 Correct answer

Enthusiast , Nov 20, 2014 Nov 20, 2014

There are various ways here is one way to show the value when it is changed.

var w, layout; 

layout = "dialog {  \

    dropdown: DropDownList { \

        size: [100,20] \

        properties: { \

            items: ['one','two','three'] \

        } \

    } \

}";

w = new Window(layout);

w.dropdown.selection=0;

w.dropdown.onChange= function(){

    alert(w.dropdown.selection.text);

}

w.show();

Votes

Translate

Translate
Adobe
Enthusiast ,
Nov 20, 2014 Nov 20, 2014

Copy link to clipboard

Copied

You just have to set the selection, example.

var w, layout; 

layout = "dialog {  \

    dropdown: DropDownList { \

        size: [100,20] \

        properties: { \

            items: ['one','two','three'] \

        } \

    } \

}";

w = new Window(layout);

w.dropdown.selection=0;

w.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
Participant ,
Nov 20, 2014 Nov 20, 2014

Copy link to clipboard

Copied

Thanks, that worked

Btw, how do I return the value that is selected?

For example, I change the dropdown to 'three' and I want it to return to me the number of the selected option.

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
Enthusiast ,
Nov 20, 2014 Nov 20, 2014

Copy link to clipboard

Copied

There are various ways here is one way to show the value when it is changed.

var w, layout; 

layout = "dialog {  \

    dropdown: DropDownList { \

        size: [100,20] \

        properties: { \

            items: ['one','two','three'] \

        } \

    } \

}";

w = new Window(layout);

w.dropdown.selection=0;

w.dropdown.onChange= function(){

    alert(w.dropdown.selection.text);

}

w.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
Participant ,
Nov 20, 2014 Nov 20, 2014

Copy link to clipboard

Copied

LATEST

Thanks guys it worked

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
Community Expert ,
Nov 20, 2014 Nov 20, 2014

Copy link to clipboard

Copied

The drop down list will show either the text or a number. with processing the result from a dropdownlist, you want to make sure you specify what you want or you will run into issues. To get the number of the selection you would werite:

alert(parseInt(w.dropdown.selection))

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
Community Expert ,
Nov 20, 2014 Nov 20, 2014

Copy link to clipboard

Copied

You need to default one. I your case 0, 1 or 2.  I don't know Photoshop ScriptUI only steal other UI example and modify for my application.   Here how a made font select-able note I set dd1 selection to 1 dd1 could also be change by remembering the previous run  and changing dd1 prior to displaying the dialog.

    dlg.msgPnl.grp6a =dlg.msgPnl.add('group');

    dlg.msgPnl.grp6a.orientation='row';

    dlg.msgPnl.grp6a.alignment='fill';

    dlg.msgPnl.grp6a.st1 = dlg.msgPnl.grp6a.add('statictext',undefined,'Font');

    fontlist = new Array();

        for (var i=0,len=app.fonts.length;i

        fontlist =  app.fonts.name;

        }

  dlg.msgPnl.grp6a.dd1 = dlg.msgPnl.grp6a.add('dropdownlist',undefined,fontlist);

  dlg.msgPnl.grp6a.dd1.selection=1;

JJMack

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