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

Manually unselect a checkbox

Explorer ,
Apr 18, 2025 Apr 18, 2025

Hello!

I have checkboxes that when selected populate on another part of my document in the order the checkbox was selected. Here is the JavaScript I am using:

if(event.target.value!="Off")
{
if(!this.getField("1").value)
{this.getField("1").value="• We reviewed and delivered your XXX."}else
if(!this.getField("2").value)
{this.getField("2").value="• We reviewed and delivered your XXX."}else
if(!this.getField("3").value)
{this.getField("3").value="• We reviewed and delivered your XXX."}else
if(!this.getField("4").value)
{this.getField("4").value="• We reviewed and delivered your XXX."}else
if(!this.getField("5").value)
{this.getField("5").value="• We reviewed and delivered your XXX."}else
if(!this.getField("6").value)
{this.getField("6").value="• We reviewed and delivered your XXX."}else
if(!this.getField("7").value)
{this.getField("7").value="• We reviewed and delivered your XXX."}else
{this.getField("8").value="• We reviewed and delivered your XXX."}
}

 

I have a reset button that when selected unchecks all the items in that section.  However, is it possible that if a specific checkbox is unselected manually, that it will unselect in the area I've designated for it to appear?

 

I added the following mouse up JavaScript to one checkbox field (to test) as an addition to the JavaScript above, but it did not work. I used the following:

if (this.getField("Check Box1").value == "Yes") {
this.getField("Check Box1").display = display.visible;
} else {
this.getField("Check Box1").display = display.hidden;
}

 

The JavaScript removed the entire checkbox instead of removing the contents of the checkbox in its designated area. 

When I deleted the JavaScript, my checkbox field did not return. When I am in Prepare Form, I can see the checkbox. When I preview my document, it disappears. 

 

I am new to JavaScript. Can someone please help me solve?

 

Thank you so much for your help!

 

TOPICS
Create PDFs , Edit and convert PDFs , How to , JavaScript , Modern Acrobat , PDF , PDF forms
134
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 18, 2025 Apr 18, 2025

You need to change the field's value, not its display. Try this:

 

if (this.getField("Check Box1").value == "Yes") {
    this.getField("Check Box1").checkThisBox(0, true);
} else {
    this.getField("Check Box1").checkThisBox(0, false);
}
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
Explorer ,
Apr 18, 2025 Apr 18, 2025

Thank you so much! Unfortunately, it did not work. When I manually uncheck the checkbox, the phrasing still appears in the section it populates. When I use the Reset button, it disappears, but everything in that section disappears. 

 

I added a separate JavaScript to the checkbox and I also added it to te JavaScript I originally created.  

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 19, 2025 Apr 19, 2025

Changing the value of the field will not trigger the Mouse Up event. It will trigger a calculation event, though, so if you move your code (and adjust it accordingly) to the calc. event of the text field then it will work.

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 18, 2025 Apr 18, 2025

Does it matter which checkbox is unchecked, can it remove last added value, or you want to remove the value added by that checkbox?

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 19, 2025 Apr 19, 2025
LATEST

Hi @Senoj Tech ,

 

Not sure if I understood your requirements correctly, but I think it may be easier to just change the export value of each checkbox from "Yes" to "• We reviewed and delivered your XXX", and use a script similar to the example below:

 

for (var j = 0; j < numFields; j ++) {
 var x = getField(getNthFieldName(j));
 (event.target.value !== "Off")? x.value = event.target.value : this.resetForm(["1"]);
 }

/*
Due credits to this post linked below for the "for loop" portion employed in the script above:
https://stackoverflow.com/questions/3611445/iterating-over-all-fields-in-a-pdf-form-with-javascript
*/

 

See how it works in my linked file here: Test File , and let us know if it helps.

 

 

NOTE:

If the fields have calculations events in them , as noted by @try67 , this solution won't work at all, or trigger errors.

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