Populate a form field based on dropdown option
Auteur : Thomas H.
Visité 913,
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
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>
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
Auteur
Ah! That is much cleaner than how I did it. I used a HTML code object on the page. Thank you.