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?

  • Suggested answer
    Eiken Profile Picture
    on at
    RE: How to call function based on trigger key pressed "Enter" on field?

    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

  • Suggested answer
    Flydancer Profile Picture
    1,332 on at
    RE: How to call function based on trigger key pressed "Enter" on field?

    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

  • Prima Kid Profile Picture
    55 on at
    RE: How to call function based on trigger key pressed "Enter" on field?

    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
    DAnny3211 Profile Picture
    9,276 Moderator on at
    RE: How to call function based on trigger key pressed "Enter" on field?

    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

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

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

#1
Siv Sagar Profile Picture

Siv Sagar 149 Super User 2025 Season 1

#2
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 53 Super User 2025 Season 1

#3
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 47

Overall leaderboard

Product updates

Dynamics 365 release plans