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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Javascript, onChange events no longer work on an empty field

(0) ShareShare
ReportReport
Posted on by 3,755

I just noticed that if you have a form field that triggers a Javascript function on the onChange event it no longer triggers the function if you clear the field, but ONLY when you change the field data. For instance; if you have a Name field populated with a name, and you remove the name - the function isn't triggered. It's left empty. You have to change the text inside the field.

Is this a bug? Please don't tell me this feature was removed? It was incredibly useful.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    ALTOSHAAM Profile Picture
    180 on at
    RE: Javascript, onChange events no longer work on an empty field

    Hi Hussman,

    This issue was solved in Service Pack 1 (support.microsoft.com/.../2941390)

    "JavaScript methods will not trigger when a business required field is changed to be blank."

    Hope this helps.

  • Taichi Sato Profile Picture
    180 on at
    RE: Javascript, onChange events no longer work on an empty field
    I found another similar issue.
    This happens at a lookup field whose field requirement is "Optional".

    step1. Set a value "ABC" to the field manually.
    step2. Remove the value "ABC" from the field by JavaScript like "Xrm.Page.getAttribute('new_account').setValue(null);"
    step3. Set the value "ABC" to the field manually again.

    Then,

    Problem1 : the OnChange event is not fired at the step3 when you set "ABC".
    Problem2 : After step3, null is returned by JavaScript "Xrm.Page.getAttribute('new_account').getValue()".
  • Ferdy Griffioen Profile Picture
    25 on at
    RE: Javascript, onChange events no longer work on an empty field

    @Tachi Sato:

    I'm also working (at the moment) with the entire attribute setNotification etc and stumbled against the same problem (like 5 minutes ago).

    I don't have a work around for it, but for our situation it is not that big of a deal.

    But just like you I hope Microsoft doesn't closes this as a 'by-design'

  • Taichi Sato Profile Picture
    180 on at
    RE: Javascript, onChange events no longer work on an empty field

    @Ferdy Griffioen:

    Assuming that "ABC" is an invalid value, when I set "ABC" to the required field, the notification "Don't input ABC!!" is displayed by the code I wrote in the onchange event.

    And I remove the value "ABC". Then, the notification is removed. (don't know why. I can't handle it anyways) And the notification is never displayed when I set "ABC" to the required field again. In this case, "ABC" could be saved.

    I hope this will not be closed with 'by-design'....

    Thanks for your reply.

  • Ferdy Griffioen Profile Picture
    25 on at
    RE: Javascript, onChange events no longer work on an empty field

    @Taichi Sato:

    I think so yeah. But the problem is that it doesn't and I think Microsoft did this 'by-design'. Because why trigger a onchange (which cost a (tiny) bit of performance) while the user can't save the entity.

  • Taichi Sato Profile Picture
    180 on at
    RE: Javascript, onChange events no longer work on an empty field

    @Ferdy Griffioen

    So, we arrived at the conclusion that the onchange should be triggered when I remove the value "ABC" at step4. If it is triggered, the onchange of step6 would be triggered too.

  • Ferdy Griffioen Profile Picture
    25 on at
    RE: Javascript, onChange events no longer work on an empty field

    @Taichi Sato:

    Step6 makes sense in a weird way.

    Because you set the value 'ABC' in the field (@ step 2) the value on that particular moment is 'ABC'. On step 4 you remove the value and the onchange is not triggerd. But at this particular moment the value (in the backend) is still 'ABC' because (for some stupid reason) the backend value is not cleared. I think this is done because the entity will not save due to a required field being empty, and thus it doesn't matter what the backend value is of that field.

  • Taichi Sato Profile Picture
    180 on at
    RE: Javascript, onChange events no longer work on an empty field

    1. Open a new record

    2. Set a value "ABC" to a required field.

    3. Move the focus

    then, the onchange event is triggered!

    4. Remove the value "ABC" from the field.

    5. Move the focus.

    then, the onchange event is NOT triggered...

    But it's still okay becaue I can not save the record anyways because it is a required field.

    The real problem comes next.

    6. Set a value "ABC" to the field again.

    then, the onchange event is NOT triggered!!

    (In case, I haven't saved the record yet, I mean, the value "ABC" is definitely a changed value.)

    My custom validation code in the onchange event is not fired, which doesn't allow the value "ABC" to be saved. Yes, I could set the validation in the onsave event but I want to show the notification when the value changes.

  • Suggested answer
    Stefano Miglietta Profile Picture
    5 on at
    RE: Javascript, onChange events no longer work on an empty field

    You are right, if the field is required the event dont fire if you are removing the value....horrible.

  • Taichi Sato Profile Picture
    180 on at
    RE: Javascript, onChange events no longer work on an empty field

    I am having the same problem. Well, actually it doesn't matter as much in my case. But I would like to know that this behavior will be changed in future or not.

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…

Mansi Soni – Community Spotlight

We are honored to recognize Mansi Soni as our August 2025 Community…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#2
Christoph Pock Profile Picture

Christoph Pock 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans