Dropdown pre-selection fails for first item/index 0

Hello! o)

Please see below code, it opens a dialog with dropdown box. The first item with index = 0 shall be preselected, but it won't.
Preselection works fine if preselection index is > 0 though. Just ncomment the //var defIndex = x lines to see the effect.

[code]@script jscript

var defIndex = 0; //preselection does not work for index 0
//var defIndex = 1; //preselection works
//var defIndex = 2; //preselection works

///////////////////////////////////////////////////////////////////////////
function OnClick(data){
var choices = DOpus.Create.Vector();
choices.push_back("0 Off");
choices.push_back("1 Xception");
choices.push_back("2 Error");

var dlg = data.func.dlg;
var result = OpenSelectBox("XLog", "Choose..", dlg, choices, defIndex);
DOpus.Output("Selected index: " + dlg.selection);

}
///////////////////////////////////////////////////////////////////////////
function OpenSelectBox(title, msg, dlg, choices, defaultIndex){
DOpus.Output("Default index: " + defaultIndex);
dlg.title = title;
dlg.message = msg;
dlg.buttons = "Ok|Cancel";
dlg.choices = choices;
dlg.selection = defaultIndex || undefined;
dlg.Show();
return dlg.result;
}
[/code]
Thank you for your attention! o)

This one is a bug in your script rather than Opus:

 dlg.selection = defaultIndex || undefined;

Change it to:

 dlg.selection = defaultIndex;

A handy code snippet @tbone... :smiley:

Regards, AB

Ooops, thank you Leo! o) Sorry for wasting your time!
I should have stripped down my actual problem-script even more, will do next time.

Offtopic, but related to my bad line of code:
My actual aim was to have the "defaultIndex" param optional in OpenSelectBox(). But if "defaultIndex == 0", the evaluation would assign "undefined" to dlg.selection, resulting in the default behaviour again (no pre-selection at all). This is how it should look like:

dlg.selection = typeof defaultIndex != "undefined" ? defaultIndex : 0;

Thanks all! o)