Skip to main content
Participant
June 3, 2020
Answered

check box equals a value in form when checked

  • June 3, 2020
  • 1 reply
  • 12878 views

I am creating a form that adds amounts for a total. I want to create a check box (BOX1), that when checked, puts a specific dollar amount in another text box  (#4) which is then added to other amounts to create a total for purchase. 

This topic has been closed for replies.
Correct answer Thom Parker

right now the script is in the actions/run javascript in Box1 and the data in box4 is read only.


You mean that the script is on a MouseUp "run a JavaScript" on the Box1 checkbox?

Ok, then the script should look like this:

 

if (event.target.isBoxChecked(0))
      this.getField("BOX4").value = 4; 
else
      this.getField("BOX4").value = 0; 

 

 

1 reply

BarlaeDC
Community Expert
Community Expert
June 3, 2020

Hi,

Something like this should work for the checkbox part :

if (this.getField("BOX1").isBoxChecked(0)){
this.getField("BOX4").value = 4; // dollar amount
}

 

Then you can just calculate the fields as normal,

 

see here for more information - https://community.adobe.com/t5/acrobat/field-calculation/td-p/10314382?page=1

 

Regards

Malcolm

pevendenAuthor
Participant
June 3, 2020

That works great.. thanks... however, if i 'uncheck' the box the amount stays in Box4.... do i need another script that says if uncheck, value is '0' ?

 

where does one find these scripts or how to make them? is there a list somewhere?

Thom Parker
Community Expert
Community Expert
November 1, 2022

Good afternoon, I have a small pdf trying to work some calculations for membership options and values.  I have tried the script below and was able for the amount to show up correctly, however when I click off the same box the value does not change and the check mark seems to not work consistently. 

 

if (event.target.isBoxChecked(0))
      this.getField("BOX4").value = 4; 
else
      this.getField("BOX4").value = 0

 Full disclosure my skills at java are minimal but will try to figure it out with some guidance.

Thanks

Doug

if (event.target.isBoxChecked(0))
      this.getField("BOX4").value = 4; 
else
      this.getField("BOX4").value = 0

 


It looks like you want the amounts associated with all check boxes added up? If this is true, then the solution provided on this thread is not suitable.

 

Instead, set the export value of all the check boxes to the associated amount. Then use the sum function on the Total field to add the checkboxes.  And be sure to delete all of the MouseUp scripts. This is critical. Get rid of those scripts. 

 

You can read more about checkboxes on PDF here:

https://www.pdfscripting.com/public/Checkboxes-and-Radio-Buttons.cfm

 

 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often