• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit Search
0

Form Field Auto Fill Based on Two Other Fields

New Here ,
Jan 20, 2023 Jan 20, 2023

Copy link to clipboard

Copied

I'm looking to auto update a form field dependent on the answers of two other dropdown fields. The two dropdowns are "state" & "county" and depending on the answer of both, would generate contact information (Phone, Email, Fax, Cell) in a third field ("contact info"). I'm very inexpierenced with code but was able to generate the county list dependant on state selection with help from: https://gist.github.com/JoelGeraci/f14d5277b910d9714a509c98f28e1e4b

 

I can post my completed code, if it would be helpful. Another note, many states have same names for counties but I would still need them to generate different information since the state is different.

Form.PNG

TOPICS
How to , JavaScript , PDF forms

Views

175

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 20, 2023 Jan 20, 2023

Copy link to clipboard

Copied

LATEST

First, set "contact info" field as multiline.

Then you can use this as custom calculation script of "contact info" field:

var str = this.getField("county").valueAsString+" "+this.getField("state").valueAsString;
var cInfo = "";

var cData = [
{CS:"Aleutians East Borough AL", Phone:"(555) 555-1234", Email:"some1@mail.com", Fax:"1-212-222 8888", Cell:"111-111-1111"},
{CS:"Autauga AK",                Phone:"(555) 555-4567", Email:"some2@mail.com", Fax:"1-333-333 3333", Cell:"222-222-2222"},
{CS:"La Paz AZ",                 Phone:"(555) 555-9876", Email:"some3@mail.com", Fax:"1-555-678 8765", Cell:"333-333-3333"}];

for(var i in cData){
if(str == cData[i].CS)
cInfo = 
"Phone:"+cData[i].Phone+"\n"+
"Email:"+cData[i].Email+"\n"+
"Fax:"+cData[i].Fax+"\n"+
"Cell:"+cData[i].Cell;}

event.value = cInfo ? cInfo : "";

 

 

Just populate 'cData' with your data, same as I did in this example.

Script will check for concatenate string of county+state ('La Paz AZ', or 'Adams IL'...etc) so make sure you populate correct info.

Other than populating 'cData' there is no need to change anything else.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines