Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Dynamics Marketing form validation (javascript)

(0) ShareShare
ReportReport
Posted on by 2

Hi,

I got a checkbox (subscription list) regarding conditions of participation (id of the checkbox field =  c9f733b0-fd5b-ec11-8f8f-000d3adf1c7e ) on my marketing form.

What I want to achieve is, if the checkbox is NOT checked the form can not be submitted and the default "required field" error message should pop up.

I found this validation sample for dynamics marketing:

MsCrmMkt.MsCrmFormLoader.on('formSubmit', function(event)

{ // sample validation - check if

document.getElementById('txt-company-name-message').style.visibility = 'hidden';

var companyName = document.getElementById('txt-company-name').value;

if (companyName !== 'Fabricam' && companyName != 'Contoso')

{ document.getElementById('txt-company-name-message').style.visibility = 'visible';

event.preventDefault();

} });

How would I need modify this javascript to reach the behaviour with "If checkbox (c9f733b0-fd5b-ec11-8f8f-000d3adf1c7e) is not checked or =! 1, dont submit the form and throw and error.

Thanks!

  • Suggested answer
    Nya Profile Picture
    Nya 29,058 on at
    RE: Dynamics Marketing form validation (javascript)

    Hi,

    The code can be something like the following:

    var isChecked = document.getElementById('c9f733b0-fd5b-ec11-8f8f-000d3adf1c7e').value;
    
    if (isChecked == false) {
        document.getElementById("isChecked").checked = true;
    }

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans