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

Need to make a fields "required" setting conditional on a marketing form

(0) ShareShare
ReportReport
Posted on by 36
Hello, I need assistance coding a field to make its /required/ setting conditional. 
 
I have not yet added the field to the form, but it will be a field called /company name/ and i want it to be visible all the time (which i can do), but required ONLY in the event that the event type = school & university OR corporate. 
 
Can someone please help me with this?
 
I have the same question (0)
  • Suggested answer
    Dengliang Li Profile Picture
    Microsoft Employee on at
    Need to make a fields "required" setting conditional on a marketing form
    Hi,
     
    It is possible to implement this functionality by inserting JavaScript into the Outbond marketing form.
        let EventType = document.getElementById("49ce3bed-4a59-ee11-be6f-002248213b02");
        let companyName = document.getElementById("81020a1e-4b59-ee11-be6f-002248213b02");
        let star = document.createElement('span');
        star.innerText="*";
        star.style.color = 'red';
        let label = document.getElementById("companyName");
        let index = EventType.selectedIndex;
        EventType.addEventListener("change",function(e){
            e.stopPropagation();
            let index = EventType.selectedIndex;
            companyName.removeAttribute('required');
            if(label.children.length !==0){
                label.removeChild(star);
            }
            if(EventType.options[index].innerText === "Corporate Event" || EventType.options[index].innerText === "School&University Events"){
            companyName.setAttribute('required',true);
            label.appendChild(star);
            }
        })
     
    1. The string in parentheses in this line of code comes from the id value of the /select/ label for the 'What Type of Event do you want to host?' field.
     
    2. The string in parentheses in this line of code comes from the id value of the /input/ label for the 'Company Name' field.
     
    3. The string in parentheses in this line of code comes from the id value of the /label/ label for the 'Company Name' field.
    This id value does not exist by default and needs to be added manually.
     
    4. The final result is shown below.
     
    I hope my answer is helpful to you! If you have any other questions, please feel free to contact me.
     
    Best Regards,
    Dengliang Li
     

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 176 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 90

#3
Pallavi Phade Profile Picture

Pallavi Phade 60

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans