Copy link to clipboard
Copied
Good Morning!
Let me preface this with up until last week i know nothing about Adobe and JavaScript.
I have a script running in my form to calulate an estimated cost based on all the selections inside the form.
The end user wants to be able to override incase of an abnormal variable. So I have a mouse up action on the field to clear the Calculation and they can manually enter an amount.
What I want is to be able to use the form reset button to add the script back.
So there are two options but i cant make either work.
Option 1:
Use the .setAction to acdd the code back hoever it is a very long string of code and im honestly not very good at this.
this.getField("Expected Cost").setAction("Calculate","SCRIPT");
How do I enter an entire string of code in that "SCRIPT" section
Option 2:
I have a hidden text box in the form that retains the Calculation Script.
When you press the reset button i need a script that will copy the Calulcation Script from "Hidden Cost" to "Expected Cost"
the Script is the below
if (this.getField("Computer").value == "Yes") {
var A = 1000
} else {
var A = 0
}
if (this.getField("Check Box2").value == "Off") {
var P = "Choose One"
} else {
var P = this.getField("Dropdown4").value};
if(P == "Desk"){
var B = 800;
} else if
(P == "Multi"){
var B = 3000;
} else if
(P == "Check"){
var B = 800;
} else if
(P == "Platform - Print Only"){
var B = 1800;
} else if
(P == "Choose One"){
var B = 0;
}
if (this.getField("Check Box3").value == "Off") {
var S = "Choose One"
} else {
var S = this.getField("Dropdown3").value};
if(S == "Adobe Standard"){
var C = 400;
} else if
(S == "Microsoft License"){
var C = 350;
} else if
(S == "Choose One"){
var C = 0;
} else if
(S == "Both"){
var C = 750;
}
if (this.getField("Check Box4").value == "Yes") {
var D = 150
} else {
var D = 0
}
if (this.getField("Check Box5").value == "Yes") {
var E = 300
} else {
var E = 0
}
if (this.getField("Check Box6").value == "Off") {
var V = "Choose One"
} else {
var V = this.getField("Dropdown10").value};
if(V == "Scanner"){
var F = 750;
} else if
(V == "Validator"){
var F = 350;
} else if
(V == "Choose One"){
var F = 0;
} else if
(V == "Both"){
var F = 1100;
}
if (this.getField("Check Box7").value == "Yes") {
var G = 350
} else {
var G = 0
}
if (this.getField("Check Box8").value == "Yes") {
var H = 300
} else {
var H = 0
}
var I = this.getField("Text12").value
event.value = A + B + C + D + E + F + G + H + I
Copy link to clipboard
Copied
This is not going to work, not like that, at least. For starters, the setAction command won't work in Reader. And option 2 won't work, either, as it will simply override the user's input.
You need to carefully think about how this should work. What are the conditions in which the user's input should override the calculated one? What if they enter a custom value into the field, but then edit one of the fields it uses for its calculation? Should it override their entered value? If not, should it ever happen? etc.
My suggestion is to use a check-box for this. When the box is ticked, the user can enter whatever value they want into the text field. When not (or the other way around, doesn't matter), the value is automatically calculated and the user can't override it.
Copy link to clipboard
Copied
This is not going to work, not like that, at least. For starters, the setAction command won't work in Reader. And option 2 won't work, either, as it will simply override the user's input.
You need to carefully think about how this should work. What are the conditions in which the user's input should override the calculated one? What if they enter a custom value into the field, but then edit one of the fields it uses for its calculation? Should it override their entered value? If not, should it ever happen? etc.
My suggestion is to use a check-box for this. When the box is ticked, the user can enter whatever value they want into the text field. When not (or the other way around, doesn't matter), the value is automatically calculated and the user can't override it.
Copy link to clipboard
Copied
PS. While your code is not broken, it can be improved quite a bit, so it's easier to read (and debug). This version should do the same as your original code:
var A = 0;
var B = 0;
var C = 0;
var D = 0;
var E = 0;
var F = 0;
var G = 0;
var H = 0;
var I = 0;
if (this.getField("Computer").valueAsString == "Yes") {
A = 1000;
}
if (this.getField("Check Box2").valueAsString != "Off") {
var P = this.getField("Dropdown4").valueAsString;
if (P == "Desk") {
B = 800;
} else if (P == "Multi") {
B = 3000;
} else if (P == "Check") {
B = 800;
} else if (P == "Platform - Print Only") {
B = 1800;
}
}
if (this.getField("Check Box3").valueAsString != "Off") {
var S = this.getField("Dropdown3").valueAsString;
if (S == "Adobe Standard") {
C = 400;
} else if (S == "Microsoft License") {
C = 350;
} else if (S == "Both") {
C = 750;
}
if (this.getField("Check Box4").valueAsString == "Yes") {
D = 150;
}
if (this.getField("Check Box5").valueAsString == "Yes") {
E = 300;
}
if (this.getField("Check Box6").valueAsString != "Off") {
var V = this.getField("Dropdown10").valueAsString;
if (V == "Scanner") {
F = 750;
} else if (V == "Validator") {
F = 350;
} else if (V == "Both") {
F = 1100;
}
}
if (this.getField("Check Box7").valueAsString == "Yes") {
G = 350;
}
if (this.getField("Check Box8").valueAsString == "Yes") {
H = 300;
}
var I = Number(this.getField("Text12").valueAsString);
event.value = A + B + C + D + E + F + G + H + I
Copy link to clipboard
Copied
Thank you for the quick response and the help.
I will try the checkbox and see what I can do!