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); };
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();
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();
Copy link to clipboard
Copied
Thank you very much for the fast answer and for your time!!!