Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

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

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
    Eiken 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
    Flydancer 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
    Prima Kid 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
    DAnny3211 9,272 Super User 2024 Season 1 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans