How to call apex method when enter key is pressed in visualforce page
Apex Class:
public class EnterKeyEvent {
public String name {get;set;}
public void apexMethod() {
system.debug('Inside Apex Method');
}
}
Visualforce Page:
<apex:page controller="EnterKeyEvent">
<script type='text/javascript'>
function check(ev) {
if (window.event && window.event.keyCode == 13 || ev.which == 13) {
callingApexMethod();
return false;
} else {
return true;
}
}
</script>
<apex:form>
<apex:actionFunction action="{!apexMethod}" name="callingApexMethod"/>
<apex:inputText value="{!name}" onkeypress="return check(event);"/>
</apex:form>
</apex:page>
Output:
Enter any text in textbox and then press 'Enter Key'.
Apex Class:
public class EnterKeyEvent {
public String name {get;set;}
public void apexMethod() {
system.debug('Inside Apex Method');
}
}
Visualforce Page:
<apex:page controller="EnterKeyEvent">
<script type='text/javascript'>
function check(ev) {
if (window.event && window.event.keyCode == 13 || ev.which == 13) {
callingApexMethod();
return false;
} else {
return true;
}
}
</script>
<apex:form>
<apex:actionFunction action="{!apexMethod}" name="callingApexMethod"/>
<apex:inputText value="{!name}" onkeypress="return check(event);"/>
</apex:form>
</apex:page>
Output:
Enter any text in textbox and then press 'Enter Key'.
No comments:
Post a Comment