Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

How do you implement an on change event for a text field in the Dynamics 365 Portal

Posted on by 70

This one is driving me crazy.  I am trying to implement an onchange event on the telephone2 field in the Dynamics 365 portal, but it doesn't fire.  I tried putting $("#telephone2").on('change', HomePhone_OnChange());in the $(document).ready(function () {} block, but it fired when the form loaded and displayed a message from the JavaScript on a blank create form.  Then when I close the message and enter a value in the telephone2 field and tab out of the field, nothing happens.  I moved the $("#telephone2").on('change', HomePhone_OnChange()); out of the $(document).ready(function () {} block, which did remove the message on load, but changing the field value still did not trigger the on change event.  Can someone please describe to me how to implement an on change event in a portal form?

*This post is locked for comments

  • Suggested answer
    Priyanka Kamble Profile Picture
    Priyanka Kamble 20 on at
    RE: How do you implement an on change event for a text field in the Dynamics 365 Portal

    I got it worked with below script:

    $(document).ready(function () {

       $("#cld_sameaswebformsfirmadministrator").change(oncheckboxChange);

    });

    function oncheckboxChange() {

       if ($('#cld_sameaswebformsfirmadministrator').prop("checked") == true) {

           $("#cld_firstname2").val($("#firstname").val());

           $("#cld_lastname2").val($("#lastname").val());

           $("#cld_jobtitle2").val($("#jobtitle").val());

           $("#cld_emailaddress2").val($("#emailaddress1").val());

           $("#telephone3").val($("#cld_phone3").val());

       }

       else {

           $("#cld_firstname2").val('');

           $("#cld_lastname2").val('');

           $("#cld_jobtitle2").val('');

           $("#cld_emailaddress2").val('');

           $("#telephone3").val('');

       }

    }

  • Daniel Wikell Profile Picture
    Daniel Wikell 2,360 on at
    RE: How do you implement an on change event for a text field in the Dynamics 365 Portal

    It is actually not all that strange as putting () after a function tells the engine to make a function call while the onchange function itself expects a parameter that is merely a function reference.

    By including it as " $("#title").change(onTitleChange()); " the parameter that is sent in to the change-function is not a function reference but instead the result of the call to onTitleChange() which is evaluated before. In your case the onTitleChange method returned nothing so it would be the same as doing "$("#title").change(undefined);"

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: How do you implement an on change event for a text field in the Dynamics 365 Portal

    Glad it is resolve. Would appreciate if you could marke the suggestion as helpful and close the thread. This may help someone else as well :)

  • jimfield Profile Picture
    jimfield 70 on at
    RE: How do you implement an on change event for a text field in the Dynamics 365 Portal

    Yes that helped.  I had () after the function name  in the .change statement, and the () throw it off and cause the function to fire on load and not when leaving the field.  If I remove the (), then the function fires when changing the actual field.  Strange.

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: How do you implement an on change event for a text field in the Dynamics 365 Portal

    Hi Jimfield,

    I tried the below code on the title field on the create case entity form and it is working as expcted. Try this code and see if this works. Also ensure that the is of the textbox is correct.

    ===========

    $(document).ready(function () {

     $("#title").change(onTitleChange);

     });

     function onTitleChange()

     {

     alert("changed111!!!");

     }

    ==============

    Hope this helps.

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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans