Help with JavaScript?
I have an adobe acrobat form with four fields,
- the first is called Type of Assignment, and it's a multiple choice field with these options to choose from: Select One, Partial, and, Full.
- The second field is Number of Leases and is a text field.
- The third field is also a text field, this one is called Cost per Lease.
I need the third to field display $10 when the user selects Partial in the first field, and $25 when the user selects Full. Choosing Select One from the first field should do nothing other than reset Cost per Lease to an empty field, I suppose. - The fourth field on the form is called Amount Due.
When the user enters a number into the Number of Leases field, the Amount Due field should display the calculation of Number of Leases X Cost per Lease.
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.
