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

Alert selected index of a dropdownlist at onChange event

Participant ,
Jul 09, 2019 Jul 09, 2019

Copy link to clipboard

Copied

I am trying to alert the selected index of a dropdownlist, for example 0 for Name 1, 1 for Name 2 etc, but instead of this I get an undefined value... Any idea what am I doing wrong?

var dropdownlist1_array = ["Name 1","Name 2","Name 3"]; 
var dropdownlist1 = panel1.add("dropdownlist", undefined, dropdownlist1_array);
  dropdownlist1.selection = 0;
  dropdownlist1.text = "Type:";
  dropdownlist1.onChange = function(){var index = dropdownlist1.selectedIndex; alert(index); };
TOPICS
Actions and scripting

Views

1.1K

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

Guide , Jul 09, 2019 Jul 09, 2019

var panel1 = new Window("dialog","test");

var dropdownlist1_array = ["Name 1","Name 2","Name 3"];

var dropdownlist1 = panel1.add("dropdownlist", undefined, dropdownlist1_array);  

  dropdownlist1.selection = 0;  

  dropdownlist1.text = "Type:"; 

  dropdownlist1.onChange = function(){ alert(this.selection.text + " Index = " + this.selection.index); };

  panel1.show();

Votes

Translate

Translate
Adobe
Guide ,
Jul 09, 2019 Jul 09, 2019

Copy link to clipboard

Copied

var panel1 = new Window("dialog","test");

var dropdownlist1_array = ["Name 1","Name 2","Name 3"];

var dropdownlist1 = panel1.add("dropdownlist", undefined, dropdownlist1_array);  

  dropdownlist1.selection = 0;  

  dropdownlist1.text = "Type:"; 

  dropdownlist1.onChange = function(){ alert(this.selection.text + " Index = " + this.selection.index); };

  panel1.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 ,
Jul 09, 2019 Jul 09, 2019

Copy link to clipboard

Copied

LATEST

Thank you very much for the fast answer and for your time!!!

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