My JSF form contain
Multiple h:inputText
and Multiple a4j:commandButton
Also
I have 2 buttons (search) and (reset)
My need when i press Enter
during editing any h:inputText
(search) button will be fired
<h:form id="searchForm" onkeypress="formKeypress();">
<h:panelGrid columns="4" >
<h:outputText value="name" />
<h:panelGroup>
<h:inputText
title="name"
value="#{myController.name}" >
</h:inputText>
<a4j:commandButton
title="name Detail"
action="#{myController.nameDetail}" >
</a4j:commandButton>
</h:panelGroup>
<h:outputText value="city" />
<h:panelGroup>
<h:inputText
title="city"
value="#{myController.city}" >
</h:inputText>
<a4j:commandButton
title="name Detail"
action="#{myController.cityDetail}" >
</a4j:commandButton>
</h:panelGroup>
</h:panelGrid>
<h:panelGrid >
<h:panelGroup>
<a4j:commandButton
id="searchButton"
value="search" title="search"
action="#{myController.search}"
render="searchResultsGrid" />
</h:panelGroup>
</h:panelGrid>
<f:verbatim>
<script type="text/javascript" >
<!--
function formKeypress() {
// if (event.keyCode == 13) {
// document.getElementById('searchForm:searchButton').click();
// return false;
// }
}
-->
</script>
</f:verbatim>
</h:form>
the problem is that
when i press Enter
during editing any h:inputText
the first a4j:commandButton
in the form will be fired
Not the (search) button
Note
I checked the answer
Default action to execute when pressing enter in a form
But that for h:commandButton
And I face JavaScript error exception
ReferenceError: event is not defined
[Break On This Error]
if (event.keyCode == 13) {