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

why Javascript/Jquery is not working on the dynamics 365 Marketing form?

(1) ShareShare
ReportReport
Posted on by 6

Hi, I have added Javascript to marketing form to perform Hide and show fields based on the selected optionset . It is working fine when implemented inside normal HTML page . But the script is not working when the same form is hosted in dynamics 365 marketing and placed inside a webpage as a iframe. Can Anyone suggest the solution.

This is the script I want to execute.

Thanks!

<script>
       
            $("#country").hide();
            $("#province").hide();
           $(document).ready(function(){
        $('#480d3de0-b223-ed11-b83d-000d3ab987d9').on('change', function() {
           
            if ( this.value == '0')
          {
            $("#country").show();
            $("#province").hide();
          }
                 
            else if(this.value=='1')
          {
            $("#country").hide();
            $("#province").show();
         }
         else{
            $("#country").hide();
            $("#province").hide();
         }
        });
    });
    </script>
I have the same question (0)
  • shivraj123 Profile Picture
    6 on at
    Javascript/Jquery is not working in Dynamics 365 Marketing forms

    Hi, I have added some functionality in my Marketing form using Javascript/Jquery. Which will hide a form fields based on selected optionset value. It is working fine when testing on normal Html page. When the same code is uploded to Dynamics marketing form and then form is hosted on a webpage as an Iframe, It is not working.Can anyone have solution? Here is the script that I am trying to implement...

    Thanks!

    <script>
           
                $("#country").hide();
                $("#province").hide();
               $(document).ready(function(){
            $('#480d3de0-b223-ed11-b83d-000d3ab987d9').on('change', function() {
               
                if ( this.value == '0')
              {
                $("#country").show();
                $("#province").hide();
              }
                     
                else if(this.value=='1')
              {
                $("#country").hide();
                $("#province").show();
             }
             else{
                $("#country").hide();
                $("#province").hide();
             }
            });
        });
        </script>

    Thanks!

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Javascript/Jquery is not working in Dynamics 365 Marketing forms

    Hi shivraj123,

    Please test this code can work or not:

    <script>

    document.getElementById('country').style.display = 'none';

    </script>

  • shivraj123 Profile Picture
    6 on at
    RE: Javascript/Jquery is not working in Dynamics 365 Marketing forms

    Actually That is also not working when we are putting JS inside Marketing form HTML code and hosting it on the external webpage.

    Actually we are hosting marketing form as an iframe into our webpage and our JS/jquery is not working.

  • Community Member Profile Picture
    on at
    RE: why Javascript/Jquery is not working on the dynamics 365 Marketing form?

    Hi shivraj123,

    When you press F12, did you get any error message?

  • shivraj123 Profile Picture
    6 on at
    RE: why Javascript/Jquery is not working on the dynamics 365 Marketing form?

    Hi Steve Zhao ,

    It doesn't show any error message. If we are running the same code in Visual studio code it is working fine(Js is working). But when the same code present inside the marketing form source code and we are hosting the form as an iframe in a webpage The JS code is not working at all.

    thanks.

  • mikeatelement Profile Picture
    20 on at
    RE: why Javascript/Jquery is not working on the dynamics 365 Marketing form?

    I'm late to this so you may have found the answer. But as an ex-front-end developer, I'm going to guess that the reaosn is that the above isn't pure javascript. It's jQuery.

    I'll bet your website loads the form before it loads jQuery, in which case, the browser won't be able to interpret the above code.

    Alternatively, if you're embedding in an iFrame onto your website, as opposed to in an injected javascript form, the browser will never be able to use jQuery on the form.

    You'll have to write the above in true, native javascript with no library specific syntax.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 258

#2
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 186

#3
Tom_Gioielli Profile Picture

Tom_Gioielli 130 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans