Copy link to clipboard
Copied
I have a form with dropdown box, basically, I want to auto-populate some data when user click on a particular dropdown item i.e if he selects "Acke, Yvonne" via dropdown then telephone filed will auto filed a phone number which I have a complete list of name and telephone number:
PS: I have a script but not sure what's wrong and not working for me?
Custom Keystroke
if( event.willCommit ) {
if(event.value == "") this.resetForm(["DeptContact","DeptEmail","DeptNumber"]); else SetFieldValues(event.value);
}
“SetFieldValues”
Document Processing > Document JavaScripts
// Place all pre-population data into a single data structure
var DeptData = { Accounting:{ contact: "Steala Damuni", email: "accounting@mycomp.com", deptnum: "cmp1234" }, Engineering:{ contact: "Frank N. Stien", email: "engineering@mycomp.com", deptnum: "eng1234" }, Marketing :{ contact: "Shelly Oughtbuks", email: "marketing@mycomp.com", deptnum: "mkt1234" }, ITSupport:{ contact: "Goah Wei", email: "it@mycomp.com", deptnum: "its1234" }};
function SetFieldValues(cDeptName) {
// Populate fields with values from the Department Data Object
this.getField("DeptContact").value = DeptData[cDeptName].contact;
this.getField("DeptEmail").value = DeptData[cDeptName].email;
this.getField("DeptNumber").value = DeptData[cDeptName].deptnum;
}
If the value contains spaces you must put it within double-quotes.
Copy link to clipboard
Copied
The names of the items in the DeptData literal object have to match the items in the drop-down field.
Copy link to clipboard
Copied
Yes, those all items are matching with the drop-down box but not working?
Copy link to clipboard
Copied
They are not matching in the file you shared.
Copy link to clipboard
Copied
I am sorry I am new to all of these coding world 😞 could you please explain a little more briefly or maybe do one example if possible?
Copy link to clipboard
Copied
I have some updates, I have managed to work the script please see the form with script HERE but there is one issue it will populate only single line dropdown item, for example, I have "Acke, Yvonne" but when I enter this item to script it won't word instead "Acke" is working fine?
So, there is something wrong with this script or am I doing wrong?
Copy link to clipboard
Copied
If the value contains spaces you must put it within double-quotes.