Dependent check boxes, how to check all previous boxes, but not the latter ones.

New Here ,
Jan 12, 2017 Jan 12, 2017

Copy link to clipboard

Copied

Hello,

I have an order form with quantities 1-60, each with a corresponding check box.  The reason is that sometimes when a client orders our product they want ten, sometimes they want 60 sometimes more.

I would like to know how to make it so that if our client wants 47, instead of checking each of the 47 boxes i pick just the 47th box and all previous boxes are checked as well.

I don't see a way to attach my file in here, but I do not mind sending it so people can see what I am trying to accomplish.

Thank you in advance for any help.

P.S. my java and coding knowledge is nil. I am an architectural draftsperson who was, for some strange reason, tasked with making all these pdf order forms. So I am really new to this pdf form making process.

I only have access to Adobe X standard (or Pro if I kick my coworker out of her computer, for some reason she has it but not me.)

TOPICS
PDF forms

Views

540

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
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , Jan 12, 2017 Jan 12, 2017

OK, let's say the fields are called "Checkbox1" to "Checkbox60". You can use a doc-level function (although you'll need Acrobat Pro to add it) with this code and then call it from the MouseUp event of each of those fields:

function tickPreviousBoxes() {

    if (event.target.value!="Off") {

        var boxNumber = Number(event.target.name.replace("Checkbox", ""));

        for (var i=1; i<boxNumber; i++) {

            this.getField("Checkbox"+i).checkThisBox(0, true);

        }

    }

}

Likes

Translate

Translate
Adobe Community Professional ,
Jan 12, 2017 Jan 12, 2017

Copy link to clipboard

Copied

Why not simply create a drop-down or a text field where they can specify how many items they want, instead of doing it with so many check-boxes?

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
community guidelines
New Here ,
Jan 12, 2017 Jan 12, 2017

Copy link to clipboard

Copied

We need our factory workers to sign and date beside each piece when it was created so that we can keep track of when and where each piece is and when it has left our factory and send to site (precast concrete products, each piece looks identical so they have different marks to differentiate). 

Below is an image of the count sheet I have created, it is then combined with each of our products which has its corresponding order form. This way i do not have to create count sheet for each individual job with the correct amount of pieces.  What I was thinking was, if there was 47 pieces, the person taking the order simply clicks 47, then all previous boxes fill with "x" or check marks or what have you and that way the factory workers don't get confused and think there are 60 pieces each time there is an order.

COUNT SHEET.jpg

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
community guidelines
Adobe Community Professional ,
Jan 12, 2017 Jan 12, 2017

Copy link to clipboard

Copied

OK, let's say the fields are called "Checkbox1" to "Checkbox60". You can use a doc-level function (although you'll need Acrobat Pro to add it) with this code and then call it from the MouseUp event of each of those fields:

function tickPreviousBoxes() {

    if (event.target.value!="Off") {

        var boxNumber = Number(event.target.name.replace("Checkbox", ""));

        for (var i=1; i<boxNumber; i++) {

            this.getField("Checkbox"+i).checkThisBox(0, true);

        }

    }

}

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
community guidelines
New Here ,
Jan 12, 2017 Jan 12, 2017

Copy link to clipboard

Copied

I greatly appreciate this. Thank you.

But I have never read or written code before, so to clarify I will have to add the name the previous checkbox each time you write "checkbox" in blue in your code? (line 03 and line 05)

and the "off" in line 02, should be the same value current check box or previous checkbox? (i think default on mine was "Yes")

Again I truly appreciate this.

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
community guidelines
Adobe Community Professional ,
Jan 12, 2017 Jan 12, 2017

Copy link to clipboard

Copied

The only thing that needs to be changed in the code above is the base name of your fields. If you let me know how they are called I'll adjust it for you. Then it needs to be placed as a doc-level script and you will need to set the MouseUp event of each check-box to execute this code:

tickPreviousBoxes();

You can do it for all of them at once, by selecting them all and then right-clicking one of them and applying it.

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
community guidelines
New Here ,
Jan 13, 2017 Jan 13, 2017

Copy link to clipboard

Copied

Each check box is named as seen in the image. P-01, P-02, P-03 etc...

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
community guidelines
Adobe Community Professional ,
Jan 13, 2017 Jan 13, 2017

Copy link to clipboard

Copied

Try this code:

function tickPreviousBoxes() {

    if (event.target.value!="Off") {

        var boxNumber = Number(event.target.name.replace("P-", ""));

        for (var i=1; i<boxNumber; i++) {

            this.getField("P-"+util.printf("%02d",i)).checkThisBox(0, true);

        }

    }

}

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
community guidelines
New Here ,
Jan 13, 2017 Jan 13, 2017

Copy link to clipboard

Copied

I have added the code, but it did not change anything.  It does seem to erase the checkbox directly above or below when I un-check it.

Capture1.PNGCapture2.PNG

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
community guidelines
New Here ,
Jan 13, 2017 Jan 13, 2017

Copy link to clipboard

Copied

Capture3.PNGCapture4.PNG

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
community guidelines
Adobe Community Professional ,
Jan 13, 2017 Jan 13, 2017

Copy link to clipboard

Copied

Check the JS Console (Ctrl+J) for errors. Also, can you share the file with us (via Dropbox, Google Drive, etc.)?

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
community guidelines
New Here ,
Jan 13, 2017 Jan 13, 2017

Copy link to clipboard

Copied

Thanks for reminding me I have dropbox lol. I haven't used it since I graduated College.

Dropbox - Count Sheet

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
community guidelines
Adobe Community Professional ,
Jan 13, 2017 Jan 13, 2017

Copy link to clipboard

Copied

You didn't set it up as I've described. The function should as a doc-level

script, under Tools - JavaScript - Document JavaScripts, and then from the

fields themselves you just need to call it.

On Fri, Jan 13, 2017 at 8:21 PM, jasonb7821922 <forums_noreply@adobe.com>

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
community guidelines
New Here ,
Jul 24, 2022 Jul 24, 2022

Copy link to clipboard

Copied

Thank you for this old post — your script worked like a charm for what I was doing.

 

Though, I'd like to ask: would it be possible to force the script to also uncheck the boxes that come after triggered one? So, for example, if a user triggered Box #50 and the script checked all the boxes up to it, a user would be able to click on Box #15 and the script would uncheck boxes up to the #15. If it's possible, how would one do it?

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
community guidelines
Adobe Community Professional ,
Jul 24, 2022 Jul 24, 2022

Copy link to clipboard

Copied

So you want the boxes before the one that was ticked to be ticked as well, and the ones after it to be unticked? If so, change the middle part of the code above to this:

 

for (var i=1; i<=50; i++) { 
	if (i==boxNumber) continue;
	this.getField("P-"+util.printf("%02d",i)).checkThisBox(0, i<boxNumber); 
} 

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
community guidelines
New Here ,
Jul 25, 2022 Jul 25, 2022

Copy link to clipboard

Copied

quote

So you want the boxes before the one that was ticked to be ticked as well, and the ones after it to be unticked?

Yes, that's the idea.

Thanks for the code, but for some reason it works only partialy: checkboxes before the one that was ticked do become ticked (so it works like before), but the ones after it are not affected at all.

 

JS Console writes that: TypeError: this.getField(...) is null, but the checkboxes seem to be named and setup appropriately. For this, I've made test checkboxes and named them from P-01 to P-04, to avoid any meddling with the script, yet the issue still persists.

 

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
community guidelines
Adobe Community Professional ,
Jul 25, 2022 Jul 25, 2022

Copy link to clipboard

Copied

This error message means that (at least) one of the fields is not named like the others. Even a single space or a missing digit (such as "P-1" instead of "P-01") will cause it to fail. If you can't locate it, share the file with us.

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
community guidelines
New Here ,
Jul 25, 2022 Jul 25, 2022

Copy link to clipboard

Copied

I have created a completely clean document to test the script, so I can't really locate an issue. From what I see, all checkboxes are named correctly. But here's the test file anyway:

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
community guidelines
Adobe Community Professional ,
Jul 25, 2022 Jul 25, 2022

Copy link to clipboard

Copied

In this case the issue is the other way around... You didn't adjust the code to stop at 5, instead of 50.

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
community guidelines
Adobe Community Professional ,
Jul 25, 2022 Jul 25, 2022

Copy link to clipboard

Copied

Sorry, 6 not 5. Also, this line should be removed from the code:

 

if (event.target.value!="Off") {

 

Fixed version is attached.

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
community guidelines
New Here ,
Jul 25, 2022 Jul 25, 2022

Copy link to clipboard

Copied

Thank you very much, that worked!

One question that I still have: if, for example, I need to have different groups of checkboxes in one document, I'd have to create a separate script for each "group", right?

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
community guidelines
Adobe Community Professional ,
Jul 25, 2022 Jul 25, 2022

Copy link to clipboard

Copied

Yes, unless the names are almost identical, in which case you could probably create a generic script for it.

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
community guidelines
New Here ,
Jul 25, 2022 Jul 25, 2022

Copy link to clipboard

Copied

So, if the names were almost identical, there would be a way to re-use the script for multiple sets of checkboxes?

 

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
community guidelines
Adobe Community Professional ,
Jul 25, 2022 Jul 25, 2022

Copy link to clipboard

Copied

Here's an example of a generic script that will work with all field names, as long as:

- they are named consistently;

- their names all end with a (2-digit) number;

- they don't have any other numbers in their name;

- the first field is always numbered 01:

 

 

function tickPreviousBoxes() { 
	var baseName = event.target.name.replace(/\d/g, "")
	var boxNumber = Number(event.target.name.replace(/\D/g, ""));
	var f = this.getField(baseName + "01");
	var i = 1;
	while (f!=null) {
		if (i!=boxNumber) {
			this.getField(baseName+util.printf("%02d",i)).checkThisBox(0, i<boxNumber);
		}
		i++;
		f = this.getField(baseName + util.printf("%02d",i));
	}
} 

 

Edited: Code fixed

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
community guidelines
New Here ,
Jul 25, 2022 Jul 25, 2022

Copy link to clipboard

Copied

For some reason the script causes Adobe to crash as soon as the boxes are "ticked".

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
community guidelines