Copy link to clipboard
Copied
Hi Guys,
Hope you can help. I have been retired now for some time and am still using Acrobat X because I no longer need the full Creative Suite.
My problem is I have forgotten or am behing the times on my Javascript. This is what I have put in on a Sheet I am building for some friends.
if ("StrengthSavingThrow".value=="Yes")
event.value = StrMod+ProficiencyBonus;
else event.value = StrMod
This is the error code I am getting.
1:AcroForm:Str Saving Throw.0:Annot1:MouseUp:Action1
getField("StrengthSavingThrow") is null
1:Field:Calculate
3:Field:Calculate
StrMod is not defined
3:Field:Calculate
ReferenceError: StrMod is not defined
3:Field:Calculate
Now I have a field StrMod and The Strength Saving Throw is the checkbox. I want it if it is not checked to use one value if checked add another value to that one.
Any help will be appreciated.
Thank you very much.
Larry
Hi, see if this works for you:
var DexMod = Number(this.getField("DexMod").value);
var ProBonus = Number(this.getField("ProBonus").value);
if(this.getField("DexSavingThrow").value != "Off"){
event.value = DexMod + ProBonus;}
else
event.value = DexMod;
Copy link to clipboard
Copied
Is ProficiencyBonus another field in the form? If so, what type of field is it? What type of field is StrMod?
Regarding the script you posted, what field did you place it in and is is a calculation script?
I'm going to guess at the answers to those questions and suggest the following custom Calculate script:
// Custom Calculate script for text field
(function () {
// Get these field values, as numbers
var StrMod = +getField("StrMod").value;
var ProficiencyBonus = +getField("ProficiencyBonus").value;
// Set this field's value
if (getField("StrengthSavingThrow").value !== "Off") {
event.value = StrMod + ProficiencyBonus;
} else {
event.value = StrMod;
}
})();
The first and last lines are there to prevent the unnecessary creation of document-global variables, which is a good thing.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Have gotten it down to one error. The script reads:
// Custom Calculate script for text field
(function () {
// Get these field values, as numbers
var DexMod = +getField("DexMod").value;
var ProBonus = +getField("ProBonus").value;
// Set this field's value
if (getField("DexSavingThrow").value !== "Off") {
event.value = DexMod + ProBonus;
} else {
event.value = DexMod;
}
The error I am getting is:
SyntaxError: missing } after function body
13:
I have tried putting a ) in various places on line 13 but it does not seem to address it.
Regards
Larry
Copy link to clipboard
Copied
Hi, see if this works for you:
var DexMod = Number(this.getField("DexMod").value);
var ProBonus = Number(this.getField("ProBonus").value);
if(this.getField("DexSavingThrow").value != "Off"){
event.value = DexMod + ProBonus;}
else
event.value = DexMod;
Copy link to clipboard
Copied
Thank you Nesa worked perfectly.
Thank you everyone for your help.
Regards,
Larry