• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Form field javascript

Community Beginner ,
Apr 17, 2018 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

TOPICS
Acrobat SDK and JavaScript , Windows

Views

605

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

Community Expert , Apr 17, 2018 Apr 17, 2018

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

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

Votes

Translate

Translate
Community Expert ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

What are you trying to achieve, exactly?

Votes

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

Votes

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 Expert ,
Apr 17, 2018 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;

Votes

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 ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

Shot! worked like a charm.

Votes

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 ,
Apr 17, 2018 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) ?

Votes

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 ,
Apr 17, 2018 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

Votes

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 Expert ,
Apr 18, 2018 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;

Votes

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 ,
Apr 18, 2018 Apr 18, 2018

Copy link to clipboard

Copied

LATEST

Perfect! thanks very much for your help!

Votes

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 Expert ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

Use

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

not

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

Votes

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