WebSite X5Help Center

 
Thomas H.
Thomas H.
User

Populate a form field based on dropdown option  en

Auteur : Thomas H.
Visité 836, Followers 1, Partagé 0  

Good moring,

I am using the Contact Form Object on my companies intranet page so employees can submit PTO requests. The "Data Submission" is configured to send the form to our HR department and the "Confirmation e-mail" is being sent to the employees supervisior for approval.

I have a dropdown box for the user to select their supervisor. Currently the user has to manually type the supervisors email address and typos often result in the supervisor not receiving the request.

Is there a way to populate the supervisor email address, based on the dropdown result? I would assume javascript could do it but my javascript knowledge is lacking and assistance would be appreciated. 

The form ids are imObjectForm_1_5 and imObjectForm_1_6

Posté le
3 RéPONSES - 1 CORRECT
Thomas H.
Thomas H.
User
Auteur

I was able to hack my way through it and make it functional. If any javascript professionals want to chime in, please feel free.

<script>
    var e = document.getElementById("imObjectForm_1_5");
    var supervisorName;
    function onChange() {
        supervisorName = e.options[e.selectedIndex].text;
        if(supervisorName === "*******"){
            document.getElementById("imObjectForm_1_6").value = "*******@*******.com";
        } else if(supervisorName === "*******"){
            document.getElementById("imObjectForm_1_6").value = "*******@*******.com";
        } else if(supervisorName === "*******"){
            document.getElementById("imObjectForm_1_6").value = "*******@*******.com";
        } else {
            document.getElementById("imObjectForm_1_6").value = "";
        }
    }
    e.onchange = onChange;
    onChange();
</script>

Lire plus
Posté le de Thomas H.
Axel  
Axel  
User

Hello Thomas,

You need to create a form like this.

Go to the page properties.

And copy your code here with your objects names (here it's my object names)

And the email will be automatically populated.

Hope this helps

Axel

Lire plus
Posté le de Axel  
Thomas H.
Thomas H.
User
Auteur

Ah! That is much cleaner than how I did it. I used a HTML code object on the page. Thank you.

Lire plus
Posté le de Thomas H.