Skip to main content

Notifications

Announcements

No record found.

Customer Insights - Journeys forum
Suggested answer

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

Posted on by 29

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>
  • mikeatelement Profile Picture
    mikeatelement 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.

  • shivraj123 Profile Picture
    shivraj123 29 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.

  • Community Member Profile Picture
    Community Member Microsoft Employee 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
    shivraj123 29 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.

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee 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
    shivraj123 29 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!

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,532 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,501 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans