Copy link to clipboard
Copied
I can auto-calculate the miles in my fillable form using the table and script below. However, I want them to be able to select an "other" as an option in the drop-downs (putting an explanation in the purpose column) so they can manually input their own miles in the miles column. How can I do that?
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
etc...
Copy link to clipboard
Copied
There are several ways to block a calculation.
But the simplest is to use the event.rc value in the calculation script.
Add this line to the top of the miles calculation code.
event.rc = Loc2 != "Other";
this could also be an "if" condition if you want to keep the calculation from proceeding. The only reason to do this is if the calculation takes time or affects other fields.
if(event.rc = (Loc1 != "Other))
{
full calculation script
}
Copy link to clipboard
Copied
Use this code:
var Loc1=this.getField("Location1").value;
var Loc2=this.getField("Location2").value;
event.rc = (Loc1 != "OTHER") || (Loc2 != "OTHER");
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}
The code must not end with a hanging "else". This will cause an error that will prevent the code from running.
Also, "OTHER" must match the selection text exactly, including case.
If the code doesn't work there may be an error somewhere. Errors are reported in the Console Window. Press (Ctrl-J).
Good Luck,
Copy link to clipboard
Copied
If user don't use dropdowns (Loc1 and Loc2) to input miles, you can use event.source like this:
if (event.source && (event.source.name=="Location1" || event.source.name=="Location2")) {
//put your script here between blue curly brackets
}
It will update the calculation only when dropdowns are interacted with.
Copy link to clipboard
Copied
There are several ways to block a calculation.
But the simplest is to use the event.rc value in the calculation script.
Add this line to the top of the miles calculation code.
event.rc = Loc2 != "Other";
this could also be an "if" condition if you want to keep the calculation from proceeding. The only reason to do this is if the calculation takes time or affects other fields.
if(event.rc = (Loc1 != "Other))
{
full calculation script
}
Copy link to clipboard
Copied
This worked! Thank you -
What could I do if they select OTHER in the Destination From column but select one of the dropdown options in the Destination To column. It won't allow me to override the miles. It only works if they select "OTHER" in both the From and To column.
Copy link to clipboard
Copied
It's just a variation in logic.
event.rc = (Loc1 != "Other") || (Loc2 != "Other");
This code blocks if "Other" is selected in either dropdown.
Copy link to clipboard
Copied
Is this what you mean? It doesn't work. I'm very new to this, so understanding takes a bit. Thank you for being so patient and helping me.
var Loc1=this.getField("Location1").value;
var Loc2=this.getField("Location2").value;
event.rc = Loc1 != "OTHER";
event.rc = Loc2 != "OTHER";
event.rc = (Loc1 != "OTHER") || (Loc2 != "OTHER");
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
Copy link to clipboard
Copied
Use this code:
var Loc1=this.getField("Location1").value;
var Loc2=this.getField("Location2").value;
event.rc = (Loc1 != "OTHER") || (Loc2 != "OTHER");
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}
The code must not end with a hanging "else". This will cause an error that will prevent the code from running.
Also, "OTHER" must match the selection text exactly, including case.
If the code doesn't work there may be an error somewhere. Errors are reported in the Console Window. Press (Ctrl-J).
Good Luck,
Copy link to clipboard
Copied
Thank you, that worked. Also, I keep forgetting to use the correct case. That's frustrating - LOL
thanks again! 🙂
Copy link to clipboard
Copied
What if they put "OTHER" in either the FROM or TO column and then put one of our dropdown locations in the other? It won't let me put in an override for mileage. How can I get around that? I hope the question makes sense.
Copy link to clipboard
Copied
So, there is a mistake in the logic. Change this line. That's all.
event.rc = (Loc1 != "OTHER") && (Loc2 != "OTHER");
Copy link to clipboard
Copied
The form could also benefit from proper table naming. This would allow you to generalize the scripts.
For example "Row1.Location1", "Row2.Location1", etc.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now