Form field javascript

Community Beginner ,
Apr 17, 2018

Copy link to clipboard

Copied

Hi, I am very rookie with Java and need a form field to check a condition then return a value, my code looks like this:

OnFocus:

event.value = this.getfield("R_15b").value;

if(event.value < 13){

Event.value = this.getfield("R_18")}

else{event.value = 0}

R_18 is a calculated field and R_15b is an input field both preceding the event however when I tab to the field it seems to pause and run the script but the field does not populate.

Please can someone assist in pointing out my error

Regards

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Use this code as the custom calculation script of "A":

event.value = (Number(this.getField("B").valueAsString)<=12) ? this.getField("C").valueAsString : 0;

TOPICS
Acrobat SDK and JavaScript, Windows

Views

178

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

Form field javascript

Community Beginner ,
Apr 17, 2018

Copy link to clipboard

Copied

Hi, I am very rookie with Java and need a form field to check a condition then return a value, my code looks like this:

OnFocus:

event.value = this.getfield("R_15b").value;

if(event.value < 13){

Event.value = this.getfield("R_18")}

else{event.value = 0}

R_18 is a calculated field and R_15b is an input field both preceding the event however when I tab to the field it seems to pause and run the script but the field does not populate.

Please can someone assist in pointing out my error

Regards

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Use this code as the custom calculation script of "A":

event.value = (Number(this.getField("B").valueAsString)<=12) ? this.getField("C").valueAsString : 0;

TOPICS
Acrobat SDK and JavaScript, Windows

Views

179

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
Apr 17, 2018 0
Most Valuable Participant ,
Apr 17, 2018

Copy link to clipboard

Copied

What are you trying to achieve, exactly?

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
Reply
Loading...
Apr 17, 2018 0
Community Beginner ,
Apr 17, 2018

Copy link to clipboard

Copied

What needs to happen is that the event field (field A) looks at a field (field B) and determines if it is less than or equal to 12, if yes, then return the value from a different field (field C), otherwise give zero.

Then there is an additional field that does the same thing but for when its greater than 12.

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
Reply
Loading...
Apr 17, 2018 0
Most Valuable Participant ,
Apr 17, 2018

Copy link to clipboard

Copied

Use this code as the custom calculation script of "A":

event.value = (Number(this.getField("B").valueAsString)<=12) ? this.getField("C").valueAsString : 0;

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
Reply
Loading...
Apr 17, 2018 0
Community Beginner ,
Apr 17, 2018

Copy link to clipboard

Copied

Shot! worked like a charm.

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
Reply
Loading...
Apr 17, 2018 0
Community Beginner ,
Apr 17, 2018

Copy link to clipboard

Copied

If I need to apply the same logic but for a range (12<("B")<18), would the logic be event.value = (Number(this.getField("B").valueAsString) >=12 && <=18) ?

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
Reply
Loading...
Apr 17, 2018 0
Community Beginner ,
Apr 17, 2018

Copy link to clipboard

Copied

Sorry for the spam, basically I need the next field to check if field B is between 12 & 18 and if so, multiply field C by 1.5

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
Reply
Loading...
Apr 17, 2018 0
Most Valuable Participant ,
Apr 18, 2018

Copy link to clipboard

Copied

In that case I would suggest to split it into individual if-conditions, like this:

var b = Number(this.getField("B").valueAsString);

var c = Number(this.getField("C").valueAsString);

if (b<=12) event.value = c;

else if (b<=18) event.value = c * 1.5;

else event.value = 0;

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
Reply
Loading...
Apr 18, 2018 1
Community Beginner ,
Apr 18, 2018

Copy link to clipboard

Copied

Perfect! thanks very much for your help!

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
Reply
Loading...
Apr 18, 2018 0
Adobe Community Professional ,
Apr 17, 2018

Copy link to clipboard

Copied

Use

event.value = this.getfield("R_18").value

not

Event.value = this.getfield("R_18")

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
Reply
Loading...
Apr 17, 2018 0