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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Add event handler on field doesn't work

(1) ShareShare
ReportReport
Posted on by

Hi everyone!

I want to add an onclick event handler on a field , so that when clicked (or focus) to hide an element.

Here is my code:

function setOnFocus()
{
    var preferredResource = document.getElementById("ral_preferredresource");
	
	if (preferredResource){
		alert("on click");
		preferredResource.attachEvent("onclick", hideFormAssistant);
	}
	
}



function hideFormAssistant()
{
  alert("in hideformassistant");
  document.getElementById('tdRelatedInformationPane').style.display = 'none';
}


Any ideas why it doesn't work? It errors on this line 

preferredResource.attachEvent("onclick", hideFormAssistant);

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Community Member Profile Picture
    on at

    Figured it out. Had to use addEventListener

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Shak,

    You use "Dom manipulations" that are not supported - that's why your code doesn't work as it expected ;) . I would suggest to find supported way to resolve your scenario.

  • Community Member Profile Picture
    on at

    Not sure if this can be done with supported way. Unfortunately the supported way most of the times is just not enough. But yes it is best practice to use it when you can!

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans