Skip to main content
mirza5313
Known Participant
February 23, 2020
Answered

How to populate a second figure from drop down box

  • February 23, 2020
  • 1 reply
  • 1890 views

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; 
} 

 

This topic has been closed for replies.
Correct answer try67

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? 


If the value contains spaces you must put it within double-quotes.

1 reply

try67
Community Expert
February 23, 2020

The names of the items in the DeptData literal object have to match the items in the drop-down field.

mirza5313
mirza5313Author
Known Participant
February 24, 2020

Yes, those all items are matching with the drop-down box but not working? 

mirza5313
mirza5313Author
Known Participant
February 24, 2020

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? 


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?