check box equals a value in form when checked

New Here ,
Jun 03, 2020

Copy link to clipboard

Copied

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. 

Adobe Community Professional
Correct answer by Thom Parker | Adobe Community Professional

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; 

 

 

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

500

Likes

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

check box equals a value in form when checked

New Here ,
Jun 03, 2020

Copy link to clipboard

Copied

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. 

Adobe Community Professional
Correct answer by Thom Parker | Adobe Community Professional

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; 

 

 

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

501

Likes

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
Jun 03, 2020 0
Adobe Community Professional ,
Jun 03, 2020

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Jun 03, 2020 0
New Here ,
Jun 03, 2020

Copy link to clipboard

Copied

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?

Likes

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
Reply
Loading...
Jun 03, 2020 0
Adobe Community Professional ,
Jun 03, 2020

Copy link to clipboard

Copied

You didn't mention any other cases in your original post. But that's easy enough to fix. Just add an "else" to the current code. 

Also, where is this script? If it is in the custom calculation script for the "BOX4" field, then it needs to be written like this:

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

 

It is very important that "event.value" is used to set the field value because this value is used in a following calculation, but more importantly, this is the correct way to handle data in calculation script. Accessing the field value external to the script can cause all kinds of problems.  

 

Likes

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
Reply
Loading...
Jun 03, 2020 0
New Here ,
Jun 03, 2020

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Jun 03, 2020 0
Adobe Community Professional ,
Jun 03, 2020

Copy link to clipboard

Copied

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; 

 

 

Likes

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
Reply
Loading...
Jun 03, 2020 0
pevenden LATEST
New Here ,
Jun 03, 2020

Copy link to clipboard

Copied

That did the trick... thanks.

Likes

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
Reply
Loading...
Jun 03, 2020 0