Copy link to clipboard
Copied
I am trying to do an if then statement on a PDF form.
The field is a calculated field A*B=C. If C<10 then C=10, else C=A*B
How do I write the is Adobe Pro on a PDF form? I have gone into properties, calculated field and nothing I have tried works.
Copy link to clipboard
Copied
Each field is a separate object, so if you have 3 fields like "A", "B", and "C" each is a unique object has a unique value. Each field has to be accessed individually, You need to get the value for field "A" in one statement, the value of field "B" in another statement.
var C = this.getField( "A").value * this.getField("B").value;
if( C < 10 ) event.value = 10;
else event.value = C;
You might see it more clearly with some code like:
var A = this.getField( "A").value; // the value of field A;
var B = this.getField( "B").value; // the value of field B;
var C = A * B; // the value of field A times the value of field B;
if( C < 10 ) {
event.value = 10; // value is 10 when product less than 10;
} else [{
event.value = C; // else value is the product;
}
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I have very little experience in this. I can get it to do the first half so it equals 10 but cannot get it to equal A*B. Here is the formula.
var C = this.getField( "A*B").value;
if( C < 10 ) event.value = 10;
else event.value = C;
What am I missing?
Copy link to clipboard
Copied
Each field is a separate object, so if you have 3 fields like "A", "B", and "C" each is a unique object has a unique value. Each field has to be accessed individually, You need to get the value for field "A" in one statement, the value of field "B" in another statement.
var C = this.getField( "A").value * this.getField("B").value;
if( C < 10 ) event.value = 10;
else event.value = C;
You might see it more clearly with some code like:
var A = this.getField( "A").value; // the value of field A;
var B = this.getField( "B").value; // the value of field B;
var C = A * B; // the value of field A times the value of field B;
if( C < 10 ) {
event.value = 10; // value is 10 when product less than 10;
} else [{
event.value = C; // else value is the product;
}
Copy link to clipboard
Copied
It worked! Thanks much
Copy link to clipboard
Copied
I am trying to transfer some calculations from Excel to a pdf form, I am wanting to do an IF then statement and know that I need to use javascript in the 'Custom Calculation Script' section but need some help to start as I am complete noob when it comes to Javascript. Here's my calculations with values removed to make it easy...any help would be a life saver
1.) =IF((A*B)/C>1,1,(A*B/C))
1.a) IF((A*B)/C>1,1,(A*B))
2.) =IF(W<7.1,"NRB",IF(W<10.1,"P","A"))
3.) =IF(W<7,"NRB",IF(W<13,"0.5",IF(W<26,"1",IF(W<40,"2",IF(W<66,"3","5")))))
Thank you,
Sincerely...Thoroughly Lost and Confused W Javascript
Copy link to clipboard
Copied
A good place to start: https://acrobatusers.com/tutorials/conditional-execution
Copy link to clipboard
Copied
Thanks try67, I looked into this further and boy this seems complex with multiple lines of code as I would need Variables for each action or event I am trying to run.
Am I anywhere close, I could give you my text fields names, which are setup as numbers, because they have defaults values in, it would be a tremendous help.
=IF((BW*MinDoseDiph)/ConcDiph>1,1,(BW*MinDoseDiph/ConcDiph))
I think if I had more help with the first I could then start some work on the others, thanks in advance.
Copy link to clipboard
Copied
Yes, it's a good idea to define a variable for the value of each field.
In the example above it would be something like this:
var BW = Number(this.getField("BW").value);
var MinDoseDiph = Number(this.getField("MinDoseDiph").value);
var ConcDiph = Number(this.getField("ConcDiph").value);
if (((BW*MinDoseDiph)/ConcDiph)>1) event.value = 1;
else event.value = (BW*MinDoseDiph)/ConcDiph;
One thing that's missing here, though, is handling the situation when ConcDiph equals zero, as that would result in division by zero, which is not allowed.
Copy link to clipboard
Copied
Awesome thank you so much I am going to give this a try; ConcDiph is a predefined default value that would never be zero
Copy link to clipboard
Copied
Would it be safe to say that this IF statement;
=IF((BW*MinDoseAce_Canine)/ConcAce_Canine>2,2,(BW*MinDoseAce_Canine))
Would look like this
var BW = Number(this.getField("BW").value);
var MinDoseAce_Canine = Number(this.getField("MinDoseAce_Canine").value);
var ConcAce_Canine = Number(this.getField("ConcAce_Canine").value);
if (((BW*MinDoseAce_Canine)/ConcAce_Canine>2) event.value = 2;
else event.value = (BW*MinDoseAce_Canine);
Comes back with a syntax error, missing ) after condition 4 : at line 5
Copy link to clipboard
Copied
The error message gives you all the info you need. You're missing a closing
")" in the line before the last...
The rest looks fine.
Copy link to clipboard
Copied
Thank you, I was able to figure it out with your assistance, now onto the hard ones...
=IF(BW<7,"NonRebreathing",IF(BW<13,"0.5",IF(BW<26,"1",IF(BW<40,"2",IF(BW<66,"3","5")))))
Do I need to set up variables for the values of "NonRebreathing" as currently they aren't related to a text field on the form...however I can set up a text field really quick for each. How do I do multiple IF statements in Javascript are the events separated by { }
Copy link to clipboard
Copied
If "NonRebreathing" is just a string of text then there's no need to define a variable or a field for it. You just just use it like that, as a string in double-quotes.
Yes, you will need to create nested if-statements, like this:
if (condition1) {
if (condition2) {
if (condition3) {
}
}
}
You can also combine multiple conditions into a single statement, like this:
if (condition1 && condition2 && condition3) {
}
Each structure is suitable for a different logic, but the code in the inner-most bracket of the first structure and in the second structure will be executed under the same scenarios.
Copy link to clipboard
Copied
Thanks for all of you help, in the creation of this form I am in the wanted to have these calculations start as "N/A"...couldn't I put something like this down.
var BW = Number(this.getField("BW").value);
if (BW==null)
{
event.value = "N/A";
}
else if(BW<7.1 && BW>0.01)
{
event.value = "NonRebreathing";
}
else if(BW>=7.1 && BW<10.1)
{
event.value= "Pediatric";
}
else if(BW>= 10.1)
{
event.value = "Adult";
}
Copy link to clipboard
Copied
Since you're converting the value to a number it can't be null. Use 0 instead.
Copy link to clipboard
Copied
Awesome thank you...is there a way to make that happen for something like this calculation?
var BW = Number(this.getField("BW").value);
var MinDoseNR_O2 = Number(this.getField("MinDoseNR_O2").value);
if (BW==0)
{
event.value = "0";
}
if (((BW*MinDoseNR_O2)/1000)<0.5) event.value = 0.5;
else event.value = (BW*MinDoseNR_O2)/1000;
Copy link to clipboard
Copied
You're missing an else-command there. Use this code:
if (BW==0) {
event.value = "0";
} else {
if (((BW*MinDoseNR_O2)/1000)<0.5) event.value = 0.5;
else event.value = (BW*MinDoseNR_O2)/1000;
}
Copy link to clipboard
Copied
Thank you so much
Copy link to clipboard
Copied
Ok...now I have a new problem, Customer would like me to highlight or blackout particular cells based on selection (radio button field choice)...my questions are;
1. Is this even possible?
2. Where would I put the calculation?
3. What would a javascript calculation even look like for this particular scenario.
I would be forever grateful in help building this out...thanks in advance for the help.
Copy link to clipboard
Copied
By "cells" do you mean form fields?
Copy link to clipboard
Copied
yes, some of the previous calculations that I have been working on are species specific and instead of recreating the forms I thought we could either blackout or highlight those calculations when a user selects or toggles between species.
Copy link to clipboard
Copied
You just need to add a condition to your calculations that if a specific value is selected in those radio-buttons then they should not show anything.
Copy link to clipboard
Copied
If my calculation is set up like the following how would I add in that condition?
var BW = Number(this.getField("BW").value);
var MinDoseAce_Canine = Number(this.getField("MinDoseAce_Canine").value);
var ConcAce_Canine = Number(this.getField("ConcAce_Canine").value);
if (((BW*MinDoseAce_Canine)/ConcAce_Canine>2)) event.value = 2;
else event.value = (BW*MinDoseAce_Canine);
Copy link to clipboard
Copied
Also if on some of the fields I opted to use simplified field notations as they didn't need custom calculation script will I now have to go back and modify it to use custom calculation for this new condition; (BW * MinDoseBupi_Canine) / ConcBupi_Canine

