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

How can I add value to text box with multiple checkbox's "checked"?

New Here ,
May 26, 2021 May 26, 2021

I have 3 different check boxes and 1 Text Field. 

I am trying to get the Text Field value to stay at 0 when none of the boxes are checked. When the checkbox "CB1" is checked I'd like the value to be 169. When checkbox "CB5" is checked I'd like the value to be 399. When "CB3" is checked I'd like the value to be 1099. Any idea how to do this? I am new to scripting! 

TOPICS
How to
3.6K
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
2 ACCEPTED SOLUTIONS
Community Expert ,
May 27, 2021 May 27, 2021

Try this:

if(this.getField("CB3").valueAsString != "Off" && this.getField("CB1").valueAsString != "Off" && this.getField("CB5").valueAsString != "Off")
event.value = 1099;
else if(this.getField("CB1").valueAsString != "Off" && this.getField("CB5").valueAsString != "Off")
event.value = 399;
else if(this.getField("CB1").valueAsString != "Off")
event.value = 169;
else event.value = 0;

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
Community Expert ,
Apr 12, 2022 Apr 12, 2022

There is no need to do all of that, just go to checkbox properties under options tab change export value of CB1 to 1,CB2 to 2 and CB3 to 3, now go to text field calculate tab and select 'Value is the...' leave it as SUM+ and click on 'pick' and select CB1,CB2,CB3, thats it.

 

About your script:

Your first 3 conditions where you compare only one checkbox will always be active, for example:

else if(this.getField("CB1").valueAsString != "Off")
event.value = 1;

will overvrite:

else if(this.getField("CB1").valueAsString != "Off" && this.getField("CB2").valueAsString != "Off")
event.value = 3;

Because first condition is true, you can fix it by changing order of conditions.

 

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
Community Expert ,
May 26, 2021 May 26, 2021

[Moderator moved from Using the Community (forums) to Acrobat.]

 

Nancy O'Shea— Product User, Community Expert & Moderator
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 26, 2021 May 26, 2021

As caclulation script of "Text Field" use this:

if(this.getField("CB1").valueAsString != "Off")
event.value = 169;
else if(this.getField("CB3").valueAsString != "Off")
event.value = 1099;
else if(this.getField("CB5").valueAsString != "Off")
event.value = 399;
else event.value = 0;

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
New Here ,
May 26, 2021 May 26, 2021

Thank you for your response. This script leaves the Text Field Value at 399. I need the value to change when different check boxes are marked! 

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

How do you use checkboxes, only one is checked or all 3 are checked, can you describe process?

 

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
New Here ,
May 27, 2021 May 27, 2021

I am using the checkboxes to add on features. If the are getting a base model then CB1 gets checked & value would be 169. If they are getting a mid-grade model then CB1 & CB5 get checked & value is 399. If they want a high end model CB 1, CB5 & CB3 all get checked & value is 1099. 

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

Try this:

if(this.getField("CB3").valueAsString != "Off" && this.getField("CB1").valueAsString != "Off" && this.getField("CB5").valueAsString != "Off")
event.value = 1099;
else if(this.getField("CB1").valueAsString != "Off" && this.getField("CB5").valueAsString != "Off")
event.value = 399;
else if(this.getField("CB1").valueAsString != "Off")
event.value = 169;
else event.value = 0;

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
New Here ,
May 27, 2021 May 27, 2021

Thank you so much! This worked perfectly. 

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
New Here ,
Apr 12, 2022 Apr 12, 2022

Hello community,


This problem corresponded to my need and I thought I had solved my case by reading this topic.
But it doesn't solve everything.

 

With the explained case I can do the following operations:
Let's take the following example as a value:
CB1 = 1
CB2= 2
CB3 = 3

So with the check boxes I get :
0 if CB1, CB2 and CB3 are not checked
6 if CB1, CB2 and CB3 are checked
1 if only CB1 is checked
2 if only CB2 is checked
3 if only CB3 is checked

 

But if  I check CB1 and CB2 I get 1, whereas I would like to get 3.
If I check CB1 and CB3, I still get 1 when I would like to get 4.

Here is the code that gives me this result. I can't understand why it doesn't work... 

would you have an idea to solve my problem ?

 

 

if(this.getField("CB1").valueAsString != "Off" && this.getField("CB2").valueAsString != "Off" && this.getField("CB3").valueAsString != "Off")
event.value = 6;

else if(this.getField("CB1").valueAsString != "Off")
event.value = 1;
else if(this.getField("CB2").valueAsString != "Off")
event.value = 2;
else if(this.getField("CB3").valueAsString != "Off")
event.value = 3;

else if(this.getField("CB1").valueAsString != "Off" && this.getField("CB2").valueAsString != "Off")
event.value = 3;
else if(this.getField("CB1").valueAsString != "Off" && this.getField("CB3").valueAsString != "Off")
event.value = 4;
else if(this.getField("CB2").valueAsString != "Off" && this.getField("CB3").valueAsString != "Off")
event.value = 5;

else event.value = 0;

 

 

Thx for your help 

 

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 ,
Apr 12, 2022 Apr 12, 2022

There is no need to do all of that, just go to checkbox properties under options tab change export value of CB1 to 1,CB2 to 2 and CB3 to 3, now go to text field calculate tab and select 'Value is the...' leave it as SUM+ and click on 'pick' and select CB1,CB2,CB3, thats it.

 

About your script:

Your first 3 conditions where you compare only one checkbox will always be active, for example:

else if(this.getField("CB1").valueAsString != "Off")
event.value = 1;

will overvrite:

else if(this.getField("CB1").valueAsString != "Off" && this.getField("CB2").valueAsString != "Off")
event.value = 3;

Because first condition is true, you can fix it by changing order of conditions.

 

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
New Here ,
Apr 13, 2022 Apr 13, 2022
LATEST

Thank you very much for your explanations and your help.
It's really great when it works when I was struggling with conditions for over an hour!

Thank you very much again

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