Copy link to clipboard
Copied
Doing a step-by-step form and want a checkbox to auto populate once all fields in a step are completed. Can you autofill (check) a check box when more than five fields need to be filled in first? If not, how would I complete with text that says "YES" instead?
Copy link to clipboard
Copied
The posted code is structural, not an actual script. So there are some issues that have to be dealt with before writing a actual script:
1) What does completed mean?
2) How to handle large numbers of fields, since my simple script puts it all in a single 'if'
So...
1) Completed usually means that the current value is different from the default value.
2) The easy way to handle a large number of arbitrary fields is to
a) put the names in an array and loop over them
b) Give them all group names using dot notation, so they can be acquired as a group.
The a) option is good for a single set of fields.
The b) option works in all situations and is particularly good for handling more than one section. I like this one best.
So, if the fields are named "Group.Territory", "Group.Region", etc.
Then this code will test for completion
var flds = this.getField("Group").getArray();
var bComplete = false;
if(flds.every(function(a){return a.value != a.defaultValue;}))
this.getField("Section1Check").value = "Yes";
else
this.getField("Section1Check").value = "Off";
Copy link to clipboard
Copied
Yes, that's possible. What are the names of the fields involved?
Copy link to clipboard
Copied
There are 15 fields: two dropdown menus ("Territory" and "Region"), 12 text boxes ("Name1", "Name2", "Name3", "Name4", "Name5", "Name6", "Email1", "Email2", "Email3", "Email4", "Email5", "Email6") and one checkbox ("1Familiarize").
Copy link to clipboard
Copied
And how should it work, exactly?
Copy link to clipboard
Copied
The posted code is structural, not an actual script. So there are some issues that have to be dealt with before writing a actual script:
1) What does completed mean?
2) How to handle large numbers of fields, since my simple script puts it all in a single 'if'
So...
1) Completed usually means that the current value is different from the default value.
2) The easy way to handle a large number of arbitrary fields is to
a) put the names in an array and loop over them
b) Give them all group names using dot notation, so they can be acquired as a group.
The a) option is good for a single set of fields.
The b) option works in all situations and is particularly good for handling more than one section. I like this one best.
So, if the fields are named "Group.Territory", "Group.Region", etc.
Then this code will test for completion
var flds = this.getField("Group").getArray();
var bComplete = false;
if(flds.every(function(a){return a.value != a.defaultValue;}))
this.getField("Section1Check").value = "Yes";
else
this.getField("Section1Check").value = "Off";
Copy link to clipboard
Copied
Yes, completed would mean any option other than default.
This is all a bit above my head as I'm just getting familiar with code in Adobe (this is a request at work).
My understanding of this is:
- group all fields using their names - a singular name (Step1) followed by . (Such as "Step1.Name1")
- Name the checkbox in question "Section1Check", in the case of the code below.
Then use the following code in the Section1Check :
var flds = this.getField("Step1").getArray();
var bComplete = false;
if(flds.every(function(a){return a.value != a.defaultValue;}))
this.getField("Section1Check").value = "Yes";
else
this.getField("Section1Check").value = "Off";
This would mean I could do the same thing for Section 2 checkbox (name Step 2's fields "Step2.2Dropdown" etc then use the same code except "Section2Check" instead?)
Copy link to clipboard
Copied
Correct!! But start off simple to make sure you've got the details worked out.
You can put the code for all the sections into the same text field calculation script.
As an advanced extension to this technique. The code could be placed in a document script as a function, where the name of the checkbox and the section name are passed into the function. Then the calculation script calls the function, rather than repeating the code. But this is unnecessary. It just make the code neater and easier to maintain.
Copy link to clipboard
Copied
Thank you so much for your help! I got it working and feel like a magician ![]()
Copy link to clipboard
Copied
You could do this with either a text field or a check box. With a text field you'd use a custom calculation script to monitor the dependent fields. like this:
if((this.getField("Field1").value == "something") && (this.getField("Field2").value == "somethingelse"))
event.value = "Yes";
else
event.value = "No";
For a checkbox you'll need to use the same technique. However, checkboxes don't have an easily accessible calculation script, so the trick is to use hidden text field for the calculation;
if((this.getField("Field1").value == "something") && (this.getField("Field2").value == "somethingelse"))
this.getField("Section1Check").value = "Yes";
else
this.getField("Section1Check").value = "Off";
Copy link to clipboard
Copied
I'm trying to understand this. I need to do this on my fillable form also. When a user enters text in a text field. I need the check box to check. If blank it's unchecked. Can sone one help me more on this. Do I enter the code in the text field? The check box does not have the option.
Copy link to clipboard
Copied
There are many ways to make changes in one field from data entered into another field. But if the relationship is one to one, then one of the best strategies is to put the script that makes the changes into the field that is being changed. The reason for this is that it is easy and automatic to detect changes in a field value, from a script on that field.
So, put the script into the text field. To be specific, add this code to the custom Validation script on the Text Field.
this.getField("Checkbox").value = (event.value == "")?"Off":"Yes";
There are two things in this code that you may need to change for your form.
1. Change "Checkbox" to the real name of the checkbox on your form.
2. If necessary, change "Yes" to the real export value of the checkbox on your form.
Copy link to clipboard
Copied
Thank you so much. Now if I can just figure out the code to hide layer based on check box. The option to show hide layers is not working.
Copy link to clipboard
Copied
If you are having an issue with "layers", then make a new forum post.
Copy link to clipboard
Copied
Is there a way to calculate any value that is greater than zero in the "something" spot? I would also like to know if there's a way to use a range of values. For example, if Field1 is any value greater than 0 and Field2 is between 1 and 5 then Field 3 is 1.
Copy link to clipboard
Copied
Yes, read this:
https://www.pdfscripting.com/public/How-to-write-an-If-statement.cfm
If you have further issues, then please post a your question to a new thread, with a complete explanation.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more