Copy link to clipboard
Copied
Right now what I have is this, but it isn't working:
var EXT = this.getField("Warranty").value;
if (Warranty = Extended) event.value = Number(this.getField("Quantity_Tablets").valueAsString) * 279
There are four different varieties of warranties with different prices, and based on clickboxes, I need to get the number multiplied by different values.
Please help!
Copy link to clipboard
Copied
Use this:
if (this.getField("Warranty").valueAsString == "Extended")
event.value = Number(this.getField("Quantity_Tablets").valueAsString) * 279;
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Where does you set the variables Warranty and Extended?
Copy link to clipboard
Copied
There is a set of radial buttons that are named "Warranty Charges" and the four Radio Button Choices are Standard, Extended, Accidental and Ext+Acc. I have renamed the button, and the field is now Warranty Charges, but it doesn't work either way.
Copy link to clipboard
Copied
You write
if (Warranty = Extended)
First, this you make the mistake EVERYONE makes. To test if things are equal, you need two equal signs == not =.
Second, you are comparing a variable called Warranty with a variable called Extended.
You must ALREADY have set Warranty and Extended to something. On the other hand if you want to get the value of a field you have to use this.getField. And if you want to compare with a string, it has to be in quotes. So, conceivably you really meant
if ( this.getField("Warranty") == "Extended" )
but we don't know your intention. Also you don't mention having a field called "Warranty".
Copy link to clipboard
Copied
I've renamed the field to "Warranty Charges" and have changed it in the rule.
This is it's current version:
var EXT = this.getField("Warranty Charges").value;
if (this.getField("Warranty Charges") == "Extended") event.value = Number(this.getField("Quantity_Tablets").valueAsString) * 279
It doesn't work either. Quantity_Tablets is the total of items ordered, so that's what I want to multiply by the dollar amount.
Copy link to clipboard
Copied
You doesn't use the value of the field "Warranty Charges".
Copy link to clipboard
Copied
Use this:
if (this.getField("Warranty").valueAsString == "Extended")
event.value = Number(this.getField("Quantity_Tablets").valueAsString) * 279;
Copy link to clipboard
Copied
This almost works. What works is that when I go from Standard to Extended to Accidental to Ext+Acc, it figures the amount. What doesn't is that it just keeps adding them togther, it never goes back to 0 for Extended when another is chosen. Do I need an "else" in there somewhere? If so, how do I write it?
Thanks so much!
Copy link to clipboard
Copied
Add:
else
event.value = 0;
Copy link to clipboard
Copied
THANK YOU! THANK YOU! THANK YOU!
Copy link to clipboard
Copied
Use "==" in the if. "=" is the assignment operator. "==" is the comparison operator.
you can read more about writing calculation scripts here:
https://www.pdfscripting.com/public/How-to-Write-a-Basic-PDF-Calculation-Script.cfm