Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Which event I should addEventListener to?

1 view
Skip to first unread message

Calvin Liu

unread,
Dec 21, 2007, 12:34:26 AM12/21/07
to dev-ext...@lists.mozilla.org
Hi, there,

I have a dialog which has a listbox and two buttons. The listbox has
some listitems in it. And some of the items are disabled.
What I want is to disable the button when user choose the disabled
items in the list. I can do this by adding an event listener to each
of the listitem.

This line works fine:
listitem.addEventListener('click', listItemSelectListener, true);

But it only response to the mouse click event. In order to handle
keyboard selection (with up/down key), which event I should listen?

I've tried 'focus' and 'select' but neither of them worked for me.
Any idea?

Thanks a lot!
Calvin

Myk Melez

unread,
Dec 21, 2007, 4:40:32 AM12/21/07
to Calvin Liu
Calvin Liu wrote:

> What I want is to disable the button when user choose the disabled items
> in the list.

That sounds strange, as in theory it shouldn't be possible for the user
to select disabled items.


> I can do this by adding an event listener to each of the
> listitem.

Note that you could instead add a single event listener to the listbox
and then get the listitem that triggered each event from
Event.originalTarget.


> This line works fine:
> listitem.addEventListener('click', listItemSelectListener, true);
>
> But it only response to the mouse click event. In order to handle
> keyboard selection (with up/down key), which event I should listen?

You should listen for the "command" event. See
XUL:Events#Common_XUL_events on MDC for more information:

http://developer.mozilla.org/en/docs/XUL:Events#Common_XUL_events

-myk

Neil

unread,
Dec 21, 2007, 6:03:09 AM12/21/07
to
Calvin Liu wrote:

> In order to handle keyboard selection (with up/down key), which event
> I should listen?
>
> I've tried 'focus' and 'select' but neither of them worked for me.
> Any idea?

"select" should work, although note that this event is fired by the
listbox rather than any of its items.

--
Warning: May contain traces of nuts.

Calvin Liu

unread,
Dec 21, 2007, 1:05:59 PM12/21/07
to Calvin Liu, dev-ext...@lists.mozilla.org
OK, reply myself. :)

I shouldn't listener to the event of listitem itself. Listen to the
'select' event of listbox is good.

- Calvin

On 20-Dec-07, at 9:34 PM, Calvin Liu wrote:

> Hi, there,
>
> I have a dialog which has a listbox and two buttons. The listbox has
> some listitems in it. And some of the items are disabled.

> What I want is to disable the button when user choose the disabled

> items in the list. I can do this by adding an event listener to each
> of the listitem.
>


> This line works fine:
> listitem.addEventListener('click', listItemSelectListener, true);
>

> But it only response to the mouse click event. In order to handle


> keyboard selection (with up/down key), which event I should listen?
>
> I've tried 'focus' and 'select' but neither of them worked for me.
> Any idea?
>

> Thanks a lot!
> Calvin
> _______________________________________________
> dev-extensions mailing list
> dev-ext...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-extensions
>
>

Calvin Liu

unread,
Dec 21, 2007, 1:06:39 PM12/21/07
to Neil, dev-ext...@lists.mozilla.org
Oh, yes, that's it! I got it too.
Thanks Neil!
- Calvin

0 new messages