Copy link to clipboard
Copied
So the user manipulates two fields which causes the other fields to automatically update. I've managed to cobble together this simple script(s).
1) This script is added to field one, Type of Assignment:
this.getField("Cost per Lease").value = ""; // Reset Cost per Lease on any change
var typeSelection = this.getField("Type of Assignment").value;
if (typeSelection == "Partial") {
this.getField("Cost per Lease").value = "$10";
} else if (typeSelection == "Full") {
this.getField("Cost per Lease").value = "$25";
}
2.) This script is associated with field 2, Number of Leases
// Previous value holder
var prevNumLeases = "";
// Function to check for value change
function hasValueChanged(fieldName) {
var currentField = this.getField(fieldName);
var currentValue = currentField.value;
if (currentValue != prevNumLeases) {
prevNumLeases = currentValue; // Update previous value
return true;
}
return false;
}
// Script to run on both Mouse Up and On Blur triggers
if (hasValueChanged("Number of Leases")) {
// Call your existing Script 2 here to calculate Amount Due
}
The end result is, I choose one of the two options in field one and nothing happens. I click in field 2 and enter the number of leases and click enter (or just click off or tab away from the field) and nothing happens. If I then click back into field one, though, the correct results are displayed in fields 3 and 4, but only then.
Any suggestions? Here's the pdf.
Thanks.
PS. when I posted this I received a message that invalid HTML was found in the message body and that it had been stripped. I don't see any changes to the JavaScript, so hopefully it's all intact.
Copy link to clipboard
Copied
Don't set dollar sign as string when you use that value in calculation, just format the field as number and add currency sign.
use this as 'Validate' script of "Type of Assignment" field:
var cost = this.getField("Cost per Lease");
if(event.value == "Partial")
cost.value = 10;
else if(event.value == "Full")
cost.value = 25;
else
cost.value = "";
For the calculation go to 'Calculate' tab of "Amount Due" field select 'Value is the' then select product(x) and 'Pick' "Number of Leases" and "Cost per Lease" fields.
Here is your file with changes made:
https://drive.google.com/file/d/1K4rMIhgr5UCq6qt0-C1Y4jqvCb2BO_ig/view?usp=sharing
Also in "Type of Assignment" field go to 'Options' tab and check 'Commit selected value immediately'.
Copy link to clipboard
Copied
Don't set dollar sign as string when you use that value in calculation, just format the field as number and add currency sign.
use this as 'Validate' script of "Type of Assignment" field:
var cost = this.getField("Cost per Lease");
if(event.value == "Partial")
cost.value = 10;
else if(event.value == "Full")
cost.value = 25;
else
cost.value = "";
For the calculation go to 'Calculate' tab of "Amount Due" field select 'Value is the' then select product(x) and 'Pick' "Number of Leases" and "Cost per Lease" fields.
Here is your file with changes made:
https://drive.google.com/file/d/1K4rMIhgr5UCq6qt0-C1Y4jqvCb2BO_ig/view?usp=sharing
Also in "Type of Assignment" field go to 'Options' tab and check 'Commit selected value immediately'.
Copy link to clipboard
Copied
Thank you, Ma'am. I've not done this kind of work before, using scripts or even calculation in PDFs, and your solution was eye opening for me. Appreciate it.
Copy link to clipboard
Copied
There are errors in your code. Check the JS Console (Ctrl+J) after changing the value of the drop-down field.