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

smart script

Explorer ,
May 07, 2021 May 07, 2021

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
1.4K
Translate
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
1 ACCEPTED SOLUTION
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.

View solution in original post

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

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.

Translate
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

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.

Translate
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
LATEST

Thank you so much.

Translate
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