# Listbox in mold select: impossible to select the first item without previously selecting any other

cvarona
554 1 6

Hi there,

just try

<window title="Listbox" border="normal">
<listbox rows="1" mold="select" id="lb">
<listitem label="Inbox" id="Inbox" />
<listitem label="Draft" id="Draft" />
</listbox>
<button label="Show selected item" onClick='Listitem li = lb.getSelectedItem(); alert( li == null? "No item selected" : String.valueOf( li ) );' />
</window>
in the online zksandbox.

According to my experience with ff it's impossible to get the 'Inbox' listitem selected unless I previously select 'Received' or 'Draft'. I'm not much sure as to what the philosofy of a dropdownlist should be, but perhaps the first item in the list should be the selected item by default.

With kind regards

César Varona

delete retag edit

## 3 Replies

cvarona
554 1 6

Or, to put it with another words: perhaps the displayed item should always be the selected item, even if the user has not performed any gesture on the listbox.

twiegand
1807 3

César,

One way to deal with this is just to set the selected index at create time.  Simply change your <listbox> to look like this:

<listbox rows="1" mold="select" id="lb" onCreate="self.setSelectedIndex(0)">


Then, in your alert you can do something like this to get the actual label (e.g. Inbox):

alert(lb.getSelectedItem().getLabel());


Regards,

Todd

cvarona
554 1 6

Hi Todd,

thanx a lot for your tip; I think it will do.

With kind regards

César Varona

[hide preview]