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
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('');
}
}
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);"
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 :)
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.
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.
Mohamed Amine Mahmoudi
83
Super User 2025 Season 1
Community Member
54
Victor Onyebuchi
6