Saturday, May 16, 2009

<apex:inputCheckBox> OnChange vs. OnClick Events

VisualForce allows most of its tags to react to JavaScript events, and they are usually quite straightforward and easy to implement. But, there are few events that can be tricky…

One of them, is the OnChange event for the <apex:inputCheckbox> tag. When a checkbox is checked or uncheck it generates the OnChange event, but only after the user selects a different input element in the page, after the checkbox loses its focus.

A better user experience could be achieved if the checkbox fired its event without waiting for the focus to be lost. This can be easily achieved using the OnClick event:
VisualForce code:

<apex:inputCheckbox onClick="{!SomeMethod}" />

No comments:

Post a Comment