web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested Answer

How to call function based on trigger key pressed "Enter" on field?

(0) ShareShare
ReportReport
Posted on by 55

Hello everybody,

I have a problem and need your help. I create a function which run on change events so need to move the cursor from field to trigger my JavaScript function, but I need to use barcode scanner. The scanner cannot automatic tab after read barcode, but it will read enter key.

How to call function based on trigger key pressed "enter" on field?

I have the same question (0)
  • Suggested answer
    DAnny3211 Profile Picture
    11,397 on at

    hi

    You can use the "onkeypress" event in JavaScript to detect when the enter key is pressed. Here's an example code snippet that you can use:

    document.getElementById("yourFieldId").onkeypress = function(e) {

     if (e.keyCode == 13) {

       // Call your function here

       yourFunction();

     }

    };

    Replace "yourFieldId" with the ID of the field you want to monitor for the enter key press, and replace "yourFunction" with the name of your function. This code will listen for the "keypress" event on the field and check if the keycode is equal to 13 (which is the keycode for the enter key). If it is, then it will call your function.

    check my answer if it helped you, thanks

    DAniele

  • Prima Kid Profile Picture
    55 on at

    hi Daniele,

    Thank you for your response. I already tried that, but cannot work. I think that syntax is deprecated for Unified Interface, aren't?

    Or any mistake on my code:

    version 1:

    document.getElementById("kre_vouchernumber").onkeypress = function(e) {

    if (e.keyCode == 13) {

      // Call your function here

      alert("work");

    }

    };

    output: TypeError: Cannot set properties of null (setting 'onkeypress') >> i think because not found the properties.

    version 2:

    Xrm.Page.getControl("kre_vouchernumber").addOnKeyPress = function(e) {

    if (e.keyCode == 13) {

      // Call your function here

      alert("work");

    }

    };

    output: nothing happened

    kindly advise.

  • Suggested answer
    Flydancer Profile Picture
    1,332 on at

    You need to use the DOM Id, not the logical name, right click on the field, chose "inspect" or something similar and search for the Id, it looks like this:

    id-84a6ae35-7795-43d9-bdd8-136c992501ac-3-first_name4273edbd-ac1d-40d3-9fb2-095c621b552d-first_name.fieldControl-text-box-text

  • Suggested answer
    Eiken Profile Picture
    on at

    Hi,

    The addonkeypress event is now deprecated and will not be supported on the unified interface (mobile included).

    You can use a custom html webresource in the form.

    Webpage (HTML) web resources (Developer Guide for Dynamics 365 Customer Engagement (on-premises)) | Microsoft Learn

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Martin Dráb Profile Picture

Martin Dráb 45 Most Valuable Professional

#2
iampranjal Profile Picture

iampranjal 36

#3
Satyam Prakash Profile Picture

Satyam Prakash 31

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans