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

checkbox or radio conditioned upon value in another field

Explorer ,
Aug 19, 2020 Aug 19, 2020

Copy link to clipboard

Copied

Hello, I am a beginner. I have a value that is a weight in "kg" to be entered on the PDF form I want a checkbox or a radio button to be ticked automatically depending on 3 ranges of the weight entered:

  • <1kg
  • 1-3kg 
  • >3kg
I would appreciate it if you could help me to script that, and where to enter this script? Thanks
(if the weight entered in the form is 2.5kg for example, only the second radio button should appear automatically)
Thanks
TOPICS
Acrobat SDK and JavaScript

Views

1.0K

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 3 Correct answers

Community Expert , Aug 19, 2020 Aug 19, 2020

If you use check-boxes with the same names and export values then you could use this script as the custom validation script "kg" to achieve it:

 

var kg = Number(event.value);
this.getField("rb1").checkThisBox(0, kg<1);
this.getField("rb2").checkThisBox(0, kg>=1 && kg<=3);
this.getField("rb3").checkThisBox(0, kg>3);

Votes

Translate

Translate
Community Expert , Aug 19, 2020 Aug 19, 2020

As the custom calculation of "C" enter the following:

 

var v = Number(this.getField("A").valueAsString) * Number(this.getField("B").valueAsString);

event.value = Math.min(3, v);

Votes

Translate

Translate
Community Expert , Aug 19, 2020 Aug 19, 2020

You can use this, then:

 

if (this.getField("CB1").valueAsString=="Off") event.value = "";
else {
var v = Number(this.getField("A").valueAsString) * Number(this.getField("B").valueAsString);
event.value = Math.min(3, v);
}

Votes

Translate

Translate
Community Expert ,
Aug 19, 2020 Aug 19, 2020

Copy link to clipboard

Copied

What's the name of the radio-button fields, and what are their export values?

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 ,
Aug 19, 2020 Aug 19, 2020

Copy link to clipboard

Copied

the names of the radio buttons are

rb1

rb2

rb3

the corresponding values:

1.5 mL

3.25 mL

5 mL

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 ,
Aug 19, 2020 Aug 19, 2020

Copy link to clipboard

Copied

What about if the "kg" field is empty?

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 ,
Aug 19, 2020 Aug 19, 2020

Copy link to clipboard

Copied

PS. you should either convert the fields to check-boxes or give them all the same name.

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 ,
Aug 19, 2020 Aug 19, 2020

Copy link to clipboard

Copied

checkboxes should be Ok too

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 ,
Aug 19, 2020 Aug 19, 2020

Copy link to clipboard

Copied

If you use check-boxes with the same names and export values then you could use this script as the custom validation script "kg" to achieve it:

 

var kg = Number(event.value);
this.getField("rb1").checkThisBox(0, kg<1);
this.getField("rb2").checkThisBox(0, kg>=1 && kg<=3);
this.getField("rb3").checkThisBox(0, kg>3);

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 ,
Aug 19, 2020 Aug 19, 2020

Copy link to clipboard

Copied

Fantastic! it worked very well, thanks a lot.

I have another variable that is a simple mutiplication of 2 others, and I want the result if exceeding numer 3, to just give the number 3 itself:

A*B=C

if C>3 then C=3

Thanks a lot for your support and 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 ,
Aug 19, 2020 Aug 19, 2020

Copy link to clipboard

Copied

As the custom calculation of "C" enter the following:

 

var v = Number(this.getField("A").valueAsString) * Number(this.getField("B").valueAsString);

event.value = Math.min(3, v);

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 ,
Aug 19, 2020 Aug 19, 2020

Copy link to clipboard

Copied

Great! 

If I want the result of this script to run at "C" only when I check a checkbox named "CB1", how should I add this condition? 

Thanks for your patience.

 

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 ,
Aug 19, 2020 Aug 19, 2020

Copy link to clipboard

Copied

Do you mean it should only show this result if CB1 is ticked?

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 ,
Aug 19, 2020 Aug 19, 2020

Copy link to clipboard

Copied

yes 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 Expert ,
Aug 19, 2020 Aug 19, 2020

Copy link to clipboard

Copied

So what should the value be when it's not ticked?

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 ,
Aug 19, 2020 Aug 19, 2020

Copy link to clipboard

Copied

it should be empty

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 ,
Aug 19, 2020 Aug 19, 2020

Copy link to clipboard

Copied

You can use this, then:

 

if (this.getField("CB1").valueAsString=="Off") event.value = "";
else {
var v = Number(this.getField("A").valueAsString) * Number(this.getField("B").valueAsString);
event.value = Math.min(3, v);
}

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 ,
Aug 19, 2020 Aug 19, 2020

Copy link to clipboard

Copied

LATEST

Wonderful!

Thanks for taking me patiently step by step, I do appreciate your help.

I learned from you and I am grateful to you.

Thanks

 

 

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 ,
Aug 19, 2020 Aug 19, 2020

Copy link to clipboard

Copied

kg can't be empty and can't be zero

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