Skip to main content
Participating Frequently
Dec 31, 2024 8:11 PM UTC
Answered

javascript for taking table information to use for calculations

I'm creating a fillable form for mileage calculations. For example, I have a table for mileage: sports center to middle school is .3 miles, sports center to senior high 2.1 miles, etc. I want people to enter location to location, and the mileage gets entered automatically. I'm fairly new to Adobe and very green with javascript. I would appreciate help. thank you

 

PDF Automation Station
Community Expert
Dec 31, 2024 10:48 PM UTC
  • Create 2 dropdowns which both contain all destinations ("SPORTS CENTER",  "TRANSPORTATION", etc.) and call them Location1 and Location2.  I developed a (paid for) tool that automates loading dropdown entries if you're interested. 
  • In the options tab of the dropdowns, check "Commit selected value immediately".
  • Enter the following custom calculation script in the mileage field:
var Loc1=this.getField("Location1").value;
var Loc2=this.getField("Location2").value;
if((Loc1=="SPORTS CENTER" && Loc2=="TRANSPORTATION")||(Loc1=="TRANSPORTATION" && Loc2=="SPORTS CENTER"))
{event.value=3.7} else
if((Loc1=="SPORTS CENTER" && Loc2=="MIDDLE SCHOOL")||(Loc1=="MIDDLE SCHOOL" && Loc2=="SPORTS CENTER"))
{event.value=2.3} else
if((Loc1=="SPORTS CENTER" && Loc2=="SENIOR HIGH")||(Loc1=="SENIOR HIGH" && Loc2=="SPORTS CENTER"))
{event.value=2.0} else
//continue pattern...
else
{event.value=""}

 

8 replies

PDF Automation Station
Community Expert
Community Expert
Dec 31, 2024 10:48 PM UTC
  • Create 2 dropdowns which both contain all destinations ("SPORTS CENTER",  "TRANSPORTATION", etc.) and call them Location1 and Location2.  I developed a (paid for) tool that automates loading dropdown entries if you're interested. 
  • In the options tab of the dropdowns, check "Commit selected value immediately".
  • Enter the following custom calculation script in the mileage field:
var Loc1=this.getField("Location1").value;
var Loc2=this.getField("Location2").value;
if((Loc1=="SPORTS CENTER" && Loc2=="TRANSPORTATION")||(Loc1=="TRANSPORTATION" && Loc2=="SPORTS CENTER"))
{event.value=3.7} else
if((Loc1=="SPORTS CENTER" && Loc2=="MIDDLE SCHOOL")||(Loc1=="MIDDLE SCHOOL" && Loc2=="SPORTS CENTER"))
{event.value=2.3} else
if((Loc1=="SPORTS CENTER" && Loc2=="SENIOR HIGH")||(Loc1=="SENIOR HIGH" && Loc2=="SPORTS CENTER"))
{event.value=2.0} else
//continue pattern...
else
{event.value=""}

 

Translate
lori_9412Author
Participating Frequently
Jan 8, 2025 4:04 PM UTC

Thank you so much for your help. I'll let you know if I need further help with this. 

 

Have a great day!

Translate