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

smart script

Explorer ,
May 07, 2021 May 07, 2021

Copy link to clipboard

Copied

Hi, I found this post https://community.adobe.com/t5/acrobat/trying-to-use-checkboxes-for-conditional-math/m-p/12008195#M3... 

that is exactly what i need, a 'smart' script that will know if bonus is applied or not. Is it possible? I tried both codes from @Thom Parker and @try67 but they are not doing what I need,they are not taking into consideration if value is already applied or not, and also with try67 code if checked checkbox is auto unchecked. Can someone pls help?

My fields are "Text1" and "Check Box1"

TOPICS
JavaScript

Views

1.2K

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 , May 07, 2021 May 07, 2021

There is a way to achive what you ask using variables.

Let's say you want to add 5 as a bonus, use this script in text field as custom calculation:

var a = 0;
var b = 0;
if(this.getField("Check Box1").valueAsString != "Off"){
var x = 1;
a = 5;}
if(x==1 && this.getField("Check Box1").valueAsString == "Off"){
b = -5;
x = 0;}
event.value = +event.value + a+b;

Even if you change value in text field it will add/remove bonus depending on checkbox state.

Votes

Translate

Translate
Enthusiast ,
May 07, 2021 May 07, 2021

Copy link to clipboard

Copied

There is no such thing as smart script, script can't think it only do what you order it to do, so there is no way that script can know if you applied bonus or not.

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 ,
May 07, 2021 May 07, 2021

Copy link to clipboard

Copied

There is a way to achive what you ask using variables.

Let's say you want to add 5 as a bonus, use this script in text field as custom calculation:

var a = 0;
var b = 0;
if(this.getField("Check Box1").valueAsString != "Off"){
var x = 1;
a = 5;}
if(x==1 && this.getField("Check Box1").valueAsString == "Off"){
b = -5;
x = 0;}
event.value = +event.value + a+b;

Even if you change value in text field it will add/remove bonus depending on checkbox state.

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
Explorer ,
May 08, 2021 May 08, 2021

Copy link to clipboard

Copied

LATEST

Thank you so much.

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