Trying to add an additional field to compare to in an if statement

Community Beginner ,
Jan 22, 2021 Jan 22, 2021

Copy link to clipboard

Copied

Hi all,

 

I am trying to get a field to compare 2 fields to get a final value. Here is the start of the if statement. I am probably missing a ) somewhere, but not sure where.

 


if(this.getField("Ability").value == "Wisdom")&&("JOT").value != "Off"{
event.value = WisMod + ProBonus;}

 

This line is where I am getting my error. The rest has been working. I tried adding this line, but it says I have an error in it.

 

Thank you for your help.

 

Regards,

 

Larry

TOPICS
PDF forms

Views

80

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct Answer

Adobe Community Professional , Jan 23, 2021 Jan 23, 2021
Off,  is default value for when checkbox is not checked (I don't belive you can change that), but you can change export value when checkbox is checked (default is 'Yes'), so if you want to use "On" you need to go to checkbox properties -> options tab -> and set export value to On.

Likes

Translate

Translate
Most Valuable Participant ,
Jan 22, 2021 Jan 22, 2021

Copy link to clipboard

Copied

You need to use the same structure you did for the Ability field, like this:

 

if (this.getField("Ability").valueAsString == "Wisdom" && this.getField("JOT").valueAsString != "Off") {
	event.value = Number(this.getField("WisMod").valueAsString) + Number(this.getField("ProBonus").valueAsString);
}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 22, 2021 Jan 22, 2021

Copy link to clipboard

Copied

I may have something wrong, but the idea here is if the Ability text field returns Wisdom and the JOT checkbox is not checked then the event value of the field I'm in which is a number is equal to the WisMod number + the ProBonus number else it will be equal to:

the WisMod number + the ProBonus number + the jotvalue Number.

 

I have all the number defined as variables. in the beginning of the scriipt.

 

Thank you for your quick reply.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Most Valuable Participant ,
Jan 22, 2021 Jan 22, 2021

Copy link to clipboard

Copied

Try this, then:

 

if (this.getField("Ability").valueAsString == "Wisdom" && this.getField("JOT").valueAsString == "Off") {
event.value = WisMod + ProBonus;
} else event.value = WisMod + ProBonus + jotvalue;

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 22, 2021 Jan 22, 2021

Copy link to clipboard

Copied

Thought it would work for other field as well, but I am doing something wrong. Here is the full script:

 

var StrMod = Number(this.getField("StrMod").value);

var ProBonus = Number(this.getField("ProBonus").value);

var jotvalue = Number(this.getField("jotvalue").value);

if(this.getField("AthleticsPro").value != "Off" && this.getField("AthleticsExp").value == "Off"){
event.value = StrMod + ProBonus;}

else

if(this.getField("AthleticsPro").value != "On" && this.getField("AthleticsExp").value == "On"){
event.value = StrMod + (ProBonus * 2);}

else

if(this.getField("JOT").value != "Off"){
event.value = StrMod + jotvalue;}

else
event.value = StrMod;

 

Thank you for your help. The On statement isn't working I have changed both to == as well and it still fails. Not sure what it is.

 

Regards,

 

Larry

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jan 23, 2021 Jan 23, 2021

Copy link to clipboard

Copied

Off,  is default value for when checkbox is not checked (I don't belive you can change that), but you can change export value when checkbox is checked (default is 'Yes'), so if you want to use "On" you need to go to checkbox properties -> options tab -> and set export value to On.

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Most Valuable Participant ,
Jan 23, 2021 Jan 23, 2021

Copy link to clipboard

Copied

Instead of !="On" use =="Off" because as was mentioned correctly above, the default on-value of fields created in Acrobat is "Yes", but the default off-value is "Off", for some reason. The former can be changed, but the latter can't.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 23, 2021 Jan 23, 2021

Copy link to clipboard

Copied

LATEST

Thank you the explanation on the fields state helped me figure out what I was doing wrong. I was able to work out the statements I needed then to make the script work.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines