Manually unselect a checkbox
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Does it matter which checkbox is unchecked, can it remove last added value, or you want to remove the value added by that checkbox?
Copy link to clipboard
Copied
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.

