How to call apex method on enter key press in Salesforce?

Sample Code:

<apex:page>

<script type='text/javascript'>
    function noenter(ev)  {
        if (window.event && window.event.keyCode == 13 || ev.which == 13) {
            callAcctRet();
            return false;
         } else {
              return true;
         }
     }
</script>

<apex:form>
    <apex:actionFunction action="{!retToAcct}" name="callAcctRet"/>
    <apex:inputText value="{!firstName}" onkeypress="return noenter(event);"/>
    <apex:form>
</apex:page>

Cheers!!!

2 comments:

  1. How to do same functionality in lightning experience. because this window function not working in lightning.

    Thanks in Advance

    ReplyDelete
    Replies
    1. Check this - http://www.infallibletechie.com/2018/09/how-to-call-javascript-method-on-enter.html

      Delete