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 :
Customer experience | Sales, Customer Insights,...
Unanswered

Add event handler to HTML Button web resource

(0) ShareShare
ReportReport
Posted on by 25

I have added an HTML Button as a Web Resource to my form.

How do I add an onClick event to trigger a function on the Form Properties js.HTML-Button.PNG

Web Rescource

<html><head>
 
    <style>
      .button {
        background-color: #4CAF50;
        border: none;
        color: white;
        padding: 5px 12px;
        text-align: center;
        text-decoration: none;
        display: inline-block;
        font-size: 16px;
        margin: 4px 2px;
        cursor: pointer;
      }

      .button {
        border-radius: 8px;
      }
    </style>
</head> <body>
        <button class="button"> Submit </button>
   
</body></html>

I have the same question (0)
  • cf-nnek Profile Picture
    10 on at

    1. Add an onclick to your button

    <button class="button" onclick="MyFunction()"> Submit </button>

    2. Add the function and do stuff you want to do

    <script>
        function MyFunction() {
            //Do whatver you want

            //For example if you want to read the value of a text field on the form
            let fieldVal = window.parent.Xrm.Page.getAttribute("myFieldName").getValue();

            //You want to get the ID of the record
            let guid = window.parent.Xrm.Page.data.entity.getId();
        }
    </script>

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 137 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 57

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans