Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Answered

How to use javascript to set a field value conditionally for a Dynamics Marketing form

Posted on by 177

Hi,

I'm building a form for a client and they have a requirement to populate certain checkboxes when another checkbox field is checked. I'm familiar with how to extend marketing forms with javascript but I just need some guidance on the actual function I would use to have it populate a checkbox field.

  • pdr469 Profile Picture
    pdr469 177 on at
    RE: How to use javascript to set a field value conditionally for a Dynamics Marketing form

    Thanks Petr. I ended up going with something similar for the solution!

  • Verified answer
    Petr Jantac Profile Picture
    Petr Jantac on at
    RE: How to use javascript to set a field value conditionally for a Dynamics Marketing form

    Hi,

    You can use the form HTML editor to include some ID to the element wrapping the text you want to hide:

    pastedimage1662383890628v1.png

    Like I did in the example above. I added id called MyTextToHide. Form editor will not remove this ID from the HTML, so you can use the Javascript to modify this field on the fly.

    Thank you.

    Petr

  • pdr469 Profile Picture
    pdr469 177 on at
    RE: How to use javascript to set a field value conditionally for a Dynamics Marketing form

    Hi Steve,

    It's a little more complex than that but yeah it needs to be when a checkbox is checked then go and check other checkboxes on the form. I'm already aware of that developer guide and I've been able to get some code to work but I'm stuck on what the actual statement is to check a checkbox field. I've done some Googling but haven't had much luck. I also have a requirement to hide some text and I can't figure out how to do that if it's not a field. It's just plain text a paragraph on the form.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to use javascript to set a field value conditionally for a Dynamics Marketing form

    Hi pdr469,

    For example, do you mean that you want to check the 'Do not email' when the 'Remember me' is checked in the following screenshot?

    pastedimage1658915073170v1.png

    You want to trigger the script when the first checkbox is checked or the form is submitted?

    Here is the doc about JS in marketing form, you could have a look:

    Extend marketing forms using code (Dynamics 365 Marketing Developer Guide) | Microsoft Docs

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans