Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
[Moderator moved from Using the Community (forums) to Acrobat.]
Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
How do you use checkboxes, only one is checked or all 3 are checked, can you describe process?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
Thank you so much! This worked perfectly.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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

