Skip to main content

Notifications

Community site session details

Community site session details

Session Id : apXdDHE58rIE9UG5mfI91U
Power Pages - General Discussions
Answered

Power Pages Form Button - JS Button Events

Like (0) ShareShare
ReportReport
Posted on 13 Jun 2023 12:26:42 by 2,143 Super User 2025 Season 1

Hello everyone,

 

I cam across a confusing problem.

As I wanted to save a variable when the submit button on a form is pressed, I could not find a event type working.

I tried the button.onSubmit() and button.onClick() after using a JQuery selector to store the Element inside it.

 

Is there a way to get the triggerevent of a button in a form? I usually take the id of the element if possible:

Lucas001_1-1686659163637.png

 

 

Lucas001_0-1686659087675.png

 

Categories:
  • Saud Ali Profile Picture
    812 Super User 2024 Season 1 on 14 Jun 2023 at 14:16:49
    Re: Power Pages Form Button - JS Button Events

    Hi @Lucas001 ,

     

    I had to experience similar scenario in the past where I had to show an extra button to do some Api calls with external system. Here is the way how you can add an additional button on Portal profile page and give you control to run your script.

     

    1- Go to Web Pages

    2- Open Profile -> Content Page

    3- Advance -> Add script

    $(document ).ready(function() {
    
     $('#ContentContainer_MainContent_MainContent_ContentBottom_SubmitButton').after('<input type="button" value="Sync With Oracle" onclick="javascript&colon;clearIsDirty();disableButtons();window.history.back();" id="CancelButton" class="btn btn-primary"/>')
    
    });

    Here are the results:

    saudali_25_0-1686752009868.png

     

    Thanks,

    Saud

     

    Please mark as verified if the answer is helpful.

     

  • Lucas001 Profile Picture
    2,143 Super User 2025 Season 1 on 14 Jun 2023 at 13:43:15
    Re: Power Pages Form Button - JS Button Events

    Thanks @Fubar and @saudali_25,

     

    to specify my problem a bit more. I have a oracledatabase as backend which needs to check the account data of the newly registered people. So that they are not allowed to make specific actions. They receive a mail and so but I also want to display a message on the profil form which tells the client that their data is currently being processed. Usually a flag is than send and javascript does the rest. Sometimes however the flow or the connection between dataverse and the power page seems to be slow or not fast enough, so that the message is not displayed.

     

    As it is the profile web form which is displayed, I cannot access it via the portal management system. Do you have another solution where I could place Javascript in? To get the click or onSubmit when I write JavaScript into the site itself, is not working on my site.

  • Verified answer
    Fubar Profile Picture
    7,850 Super User 2025 Season 1 on 13 Jun 2023 at 22:12:16
    Re: Power Pages Form Button - JS Button Events

    Similar to the post above from saudali.  It may depend on exactly what you are trying to do (e.g. if you needed to capture the User making the submission you would use form Metadata and not something on the Submit, similarly some values you may set on create/change using a Workflow or Plugin code).

    When the Submit button is pressed the form will call a Validator, that you can add your own validations to (so this is one place that you know the submit button has been pressed and may be able to add what you want in there).

    https://learn.microsoft.com/en-us/power-pages/configure/add-custom-javascript#additional-client-side-field-validation

     

  • Saud Ali Profile Picture
    812 Super User 2024 Season 1 on 13 Jun 2023 at 14:11:57
    Re: Power Pages Form Button - JS Button Events

    Hi @Lucas001 ,

     

    I'm unsure, what is your actual use case but generally whenever we have to do some sort of validation etc. on form submission, we do by using jQuery. You can navigate to Additional setting if you're using a Basic Form and put your script there.

    Here is the sample script for reference:

    if (window.jQuery) {
    (function ($) {
    if (typeof (entityFormClientValidate) != 'undefined') {
    var originalValidationFunction = entityFormClientValidate;
    if (originalValidationFunction && typeof (originalValidationFunction) == "function") {
    entityFormClientValidate = function() {
    originalValidationFunction.apply(this, arguments);
    // do your custom validation here
    // return false; // to prevent the form submit you need to return false
    // end custom validation.
    return true;
    };
    }
    }
    }(window.jQuery));
    }

     

    If you have added a custom button on form, then you can capture events by jQuery as well.

     

    Please mark as verified if the answer is helpful.

     

    Thanks

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,771 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,091 Most Valuable Professional

Leaderboard