WebSite X5Help Center

 
Thomas H.
Thomas H.
User

Populate a form field based on dropdown option  en

Autor: Thomas H.
Visited 832, Followers 1, Udostępniony 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

Posted on the
3 ODPOWIEDZI - 1 PRAWIDłOWA ODPOWIEDź
Thomas H.
Thomas H.
User
Autor

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>

Czytaj więcej
Posted on the from 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

Czytaj więcej
Posted on the from Axel  
Thomas H.
Thomas H.
User
Autor

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

Czytaj więcej
Posted on the from Thomas H.