Handle ENTER event key press in visual force page OR
Preventing default form submission and calling an action instead
Preventing default form submission and calling an action instead
<apex:page standardController="account" >
<script type="text/javascript">
function submitListener(e){
var keynum = 0;
if (window.event){
keynum = window.event.keyCode;
}
else if (e.which){
keynum = e.which;
}
// Here we check whether the Enter button was pressed
if (keynum == 13){
onFormSubmit();
}
}
<script type="text/javascript">
function submitListener(e){
var keynum = 0;
if (window.event){
keynum = window.event.keyCode;
}
else if (e.which){
keynum = e.which;
}
// Here we check whether the Enter button was pressed
if (keynum == 13){
onFormSubmit();
}
}
</script>
<apex:form id="orderSearchForm" onkeyup="submitListener(event)">
<apex:actionFunction
name="onFormSubmit" action="{!save}"
/>
<apex:pageBlock title="View
AND Edit">
<apex:pageBlockButtons >
<!-- --> <apex:commandButton
action="{!cancel}" value="Cancel"/>
<apex:commandButton
action="{!save}" value=":-)" />
<apex:commandButton action="{!cancel}"
value="Cancel"/>
</apex:pageBlockButtons>
<apex:pageblockSection columns="2">
<apex:pageblockSection
columns="1">
Name: {!account.name}
</apex:pageblockSection>
<apex:pageblockSection
columns="1">
<apex:inputField value="{!account.name}" />
<apex:inputField value="{!account.type}" />
<apex:inputField value="{!account.industry}"/>
<apex:inputField value="{!account.fax}" />
</apex:pageblockSection>
</apex:pageblockSection>
</apex:pageBlock>
</apex:form>
</apex:page>