onkeypress="return submitEnter(Id_of_button_to_click_on_enter, event);"
where submitEnter method is as defined below:
function submitEnter(commandId,e) {
var keycode;
if (window.event)
keycode = window.event.keyCode;
else if (e)
keycode = e.which;
else
return true;
if (keycode == 13) {
document.getElementById(commandId).click();
return false;
} else
return true;
}
In my case, the elements of the form were simply
'loginForm:changepwdbtn’ – is the id of the button to be clicked when user hits ‘Enter’.
As shown above, call submitEnter() on ‘onkeypress’ of all the elements where you want to use Enter button to perform some action.
Same logic applies to click a command link on Enter, only change is in the submitEnter method.
Instead of
document.getElementById(commandId).click();
use
clickLink(commandId);
where definition of clickLink() is as below:
function clickLink(linkId) {
var fireOnThis = document.getElementById(linkId)
if (document.createEvent) {
var evObj = document.createEvent('MouseEvents')
evObj.initEvent( 'click', true, false )
fireOnThis.dispatchEvent(evObj)
} else if (document.createEventObject) {
fireOnThis.fireEvent('onclick')
}
}
P.S: What I observed (may not be true for all) is that, first
And also http://wiki.apache.org/myfaces/SubmitPageOnValueChange should be very useful.
Hope this helps!
No comments:
Post a Comment