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!
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"
...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 = "";
}
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.
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";
}