Highlighted

Fillable PDF - Populate one Field based on another

Community Beginner ,
Oct 02, 2020

Copy link to clipboard

Copied

Updating a paper form to a fillable PDF.

Three pieces of information are required.  Inspector, ID Number and Territory

I have a drop down of inspector names.  The IDNumber and Territory will change depending on the name that is chosen.  

 

Would I set up a Javascript Action on the Inspector Field and populate the other from there, or set up a Javascript Action on the other two fields?

 

Can anyone give me a quick example of how this might look?  My Javascript skills have rusted from 10 years of no use.  🙂

Thanks!

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

You can do it either way. If you want the user to be able to fill in those fields manually at some point then you can use the Valiadtion event of the drop-down. That also has the advantage of having all the code in a single location.

An example script for that would be:

 

if (event.value=="John Doe") {

this.getField("ID").value = "123";

this.getField("Territory").value = "Alaska";

} else if (event.value=="Mary Jane") {

this.getField("ID").value = "456";

this.getField("Territory").value = "Idaho";

} // etc.

else {

this.getField("ID").value = "";

this.getField("Territory").value = "";

}

TOPICS
Create PDFs, Edit and convert PDFs, PDF forms

Views

47

Likes

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

Fillable PDF - Populate one Field based on another

Community Beginner ,
Oct 02, 2020

Copy link to clipboard

Copied

Updating a paper form to a fillable PDF.

Three pieces of information are required.  Inspector, ID Number and Territory

I have a drop down of inspector names.  The IDNumber and Territory will change depending on the name that is chosen.  

 

Would I set up a Javascript Action on the Inspector Field and populate the other from there, or set up a Javascript Action on the other two fields?

 

Can anyone give me a quick example of how this might look?  My Javascript skills have rusted from 10 years of no use.  🙂

Thanks!

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

You can do it either way. If you want the user to be able to fill in those fields manually at some point then you can use the Valiadtion event of the drop-down. That also has the advantage of having all the code in a single location.

An example script for that would be:

 

if (event.value=="John Doe") {

this.getField("ID").value = "123";

this.getField("Territory").value = "Alaska";

} else if (event.value=="Mary Jane") {

this.getField("ID").value = "456";

this.getField("Territory").value = "Idaho";

} // etc.

else {

this.getField("ID").value = "";

this.getField("Territory").value = "";

}

TOPICS
Create PDFs, Edit and convert PDFs, PDF forms

Views

48

Likes

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
Oct 02, 2020 0
Most Valuable Participant ,
Oct 02, 2020

Copy link to clipboard

Copied

You can do it either way. If you want the user to be able to fill in those fields manually at some point then you can use the Valiadtion event of the drop-down. That also has the advantage of having all the code in a single location.

An example script for that would be:

 

if (event.value=="John Doe") {

this.getField("ID").value = "123";

this.getField("Territory").value = "Alaska";

} else if (event.value=="Mary Jane") {

this.getField("ID").value = "456";

this.getField("Territory").value = "Idaho";

} // etc.

else {

this.getField("ID").value = "";

this.getField("Territory").value = "";

}

Likes

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
Reply
Loading...
Oct 02, 2020 0
Community Beginner ,
Oct 08, 2020

Copy link to clipboard

Copied

This works for what I was trying to do.  Works great!   There is talk about adding one more dropdown for Inspection Type.   We would populate our inspector list based on the selection in Inspection Type.  Any pointers for this type of request.

Likes

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
Reply
Loading...
Oct 08, 2020 0
try67 LATEST
Most Valuable Participant ,
Oct 08, 2020

Copy link to clipboard

Copied

You can add nested if-statements, or additional conditions, like this:

 

 

var inspectionType = this.getField("InspectionType").valueAsString;

if (event.value=="John Doe" && inspectionType=="Regular") {

this.getField("ID").value = "123";

this.getField("Territory").value = "Alaska";

} else if (event.value=="John Doe" && inspectionType=="Premium") {

this.getField("ID").value = "999";

this.getField("Territory").value = "Hawaii";

}

Likes

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
Reply
Loading...
Oct 08, 2020 0