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

javascript for taking table information to use for calculations

Community Beginner ,
Dec 31, 2024 Dec 31, 2024

Copy link to clipboard

Copied

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

lori_9412_0-1735675709194.png

 

TOPICS
How to , JavaScript , PDF forms

Views

117

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
1 ACCEPTED SOLUTION
Community Expert ,
Dec 31, 2024 Dec 31, 2024

Copy link to clipboard

Copied

  • 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=""}

 

View solution in original post

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
Community Expert ,
Dec 31, 2024 Dec 31, 2024

Copy link to clipboard

Copied

  • 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=""}

 

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
Community Beginner ,
Jan 08, 2025 Jan 08, 2025

Copy link to clipboard

Copied

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

 

Have a great day!

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
Community Beginner ,
Jan 08, 2025 Jan 08, 2025

Copy link to clipboard

Copied

I have another question: Are there any suggestions for entering "other" in the same dropdown, where they can enter their own From/To destinations and mileage? 

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
Community Expert ,
Jan 08, 2025 Jan 08, 2025

Copy link to clipboard

Copied

Add "Other" to the dropdowns and create the fields for to, from, and milege.  Modify the script so that if the dropdown value is "Other", pull the mileage from the mileage field entry value.

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
Community Beginner ,
Jan 08, 2025 Jan 08, 2025

Copy link to clipboard

Copied

If their From To isn't in the dropdown, I would like them to enter their From To manually and then manually put the mileage in the mileage column. Is that possible to do? 

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
Community Expert ,
Jan 08, 2025 Jan 08, 2025

Copy link to clipboard

Copied

Yes.  In the options tab of the dropdown field properties select Allow user to enter custom text.  Since the mileage field is calculated they will not be able to enter a number, as it will revert to the calculated value.  You will have to modify the calculation according to these instructions:

https://pdfautomationstation.substack.com/p/another-method-for-calculation-vs

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
Community Beginner ,
Jan 10, 2025 Jan 10, 2025

Copy link to clipboard

Copied

I've tried to "continue the pattern", but I'm not doing it right. Can you please tell me what I'm doing wrong? 

Here is what the form looks like and how I've labeled things. 

lori_9412_0-1736523034225.png

This is how I've entered the table into the first row MilesRow1 

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
if((Loc1=="Sports Center" && Loc2=="Education Center")||(Loc1=="Senior High" && Loc2=="Sports Center"))
{event.value=3.1} else
if((Loc1=="Sports Center" && Loc2=="Central Learning Center/STEP")||(Loc1=="Central Learning Center/STEP" && Loc2=="Sports Center"))
{event.value=3.1} else
if((Loc1=="Sports Center" && Loc2=="Forest View Elementary")||(Loc1=="Forest View Elementary" && Loc2=="Sports Center"))
{event.value=2.9} else
if((Loc1=="Sports Center" && Loc2=="Forest Lake Elementary")||(Loc1=="Forest Lake Elementary" && Loc2=="Sports Center"))
{event.value=3.0} else
if((Loc1=="Sports Center" && Loc2=="Scandia Elementary")||(Loc1=="Scandia Elementary" && Loc2=="Sports Center"))
{event.value=10.6} else
if((Loc1=="Sports Center" && Loc2=="Linwood Elementary")||(Loc1=="Linwood Elementary" && Loc2=="Sports Center"))
{event.value=13.4} else
if((Loc1=="Sports Center" && Loc2=="Wyoming Elementary")||(Loc1=="Wyoming Elementary" && Loc2=="Sports Center"))
{event.value=6.2} else
if((Loc1=="Sports Center" && Loc2=="Lino Lakes Elementary")||(Loc1=="Lino Lakes Elementary" && Loc2=="Sports Center"))
{event.value=8.7} else
if((Loc1=="Sports Center" && Loc2=="District Office")||(Loc1=="District Office" && Loc2=="Sports Center"))
{event.value=1.5} else
if((Loc1=="Sports Center" && Loc2=="Columbus Elementary")||(Loc1=="Columbus Elementary" && Loc2=="Sports Center"))
{event.value=7.0} else
var Loc1a=this.getField("Location1a").value;
var Loc2a=this.getField("Location2a").value;
if((Loc1a=="TRANSPORTATION" && Loc2a=="SPORTS CENTER")||(Loc1a=="SPORTS CENTER" && Loc2a=="TRANSPORTATION"))
{event.value=3.7} else
if((Loc1a=="TRANSPORTATION" && Loc2a=="MIDDLE SCHOOL")||(Loc1a=="MIDDLE SCHOOL" && Loc2a=="TRANSPORTATION"))
{event.value=2.7} else
if((Loc1a=="TRANSPORTATION" && Loc2a=="SENIOR HIGH")||(Loc1a=="SENIOR HIGH" && Loc2a=="TRANSPORTATION"))
{event.value=2.1} else
if((Loc1a=="TRANSPORTATION" && Loc2a=="EDUCATION CENTER")||(Loc1a=="EDUCATION CENTER" && Loc2a=="TRANSPORTATION"))
{event.value=1.4} else
if((Loc1a=="TRANSPORTATION" && Loc2a=="CENTRAL LEARNING CENTER/STEP")||(Loc1a=="CENTRAL LEARNING CENTER/STEP" && Loc2a=="TRANSPORTATION"))
{event.value=0.9} else
if((Loc1a=="TRANSPORTATION" && Loc2a=="FOREST VIEW ELEMENTARY")||(Loc1a=="FOREST VIEW ELEMENTARY" && Loc2a=="TRANSPORTATION"))
{event.value=1.1} else
if((Loc1a=="TRANSPORTATION" && Loc2a=="FOREST LAKE ELEMENTARY")||(Loc1a=="FOREST LAKE ELEMENTARY" && Loc2a=="TRANSPORTATION"))
{event.value=1.0} else
if((Loc1a=="TRANSPORTATION" && Loc2a=="SCANDIA ELEMENTARY")||(Loc1a=="SCANDIA ELEMENTARY" && Loc2a=="TRANSPORTATION"))
{event.value=10.4} else
if((Loc1a=="TRANSPORTATION" && Loc2a=="LINWOOD ELEMENTARY")||(Loc1a=="LINWOOD ELEMENTARY" && Loc2a=="TRANSPORTATION"))
{event.value=10.0} else
if((Loc1a=="TRANSPORTATION" && Loc2a=="WYOMING ELEMENTARY")||(Loc1a=="WYOMING ELEMENTARY" && Loc2a=="TRANSPORTATION"))
{event.value=2.8} else
if((Loc1a=="TRANSPORTATION" && Loc2a=="LINO LAKES ELEMENTARY")||(Loc1a=="LINO LAKES ELEMENTARY" && Loc2a=="TRANSPORTATION"))
{event.value=11.0} else
if((Loc1a=="TRANSPORTATION" && Loc2a=="DISTRICT OFFICE")||(Loc1a=="DISTRICT OFFICE" && Loc2a=="TRANSPORTATION"))
{event.value=2.5} else
if((Loc1a=="TRANSPORTATION" && Loc2a=="COLUMBUS ELEMENTARY")||(Loc1a=="COLUMBUS ELEMENTARY" && Loc2a=="TRANSPORTATION"))
{event.value=3.7} else
{event.value=""}

 

 

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
Community Beginner ,
Jan 10, 2025 Jan 10, 2025

Copy link to clipboard

Copied

LATEST

Never mind. I figured it out! Capital letters!!!

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