Copy link to clipboard
Copied
Hello,
I have a document with a lot of different checkboxes and they all have their own specific category.
I have the document so that when a user clicks on a checkbox under that specific category, a button displays a value of the number of checkmarks that are clicked under that specific category. The program will only display a value, if the checkbox string value is in the array which I DEFINE.
I have had to manually type in the specific checkbox name into array to get this done, but I am looking to see if I can iterate through and select a specific set of checkboxes to then PUSH to an array, so I don't have to manually type the string names of 100+ checkboxes.
Here is the code that I put in my custom calculation script of the text field which displays the number of checkboxes typed in:
var checkboxes = ["holter-48hr", "holter-72hr", "holter-1wk", "holter-2wk", "cardio-ecgharmonic", "cardio-loop", "cardio-restingecg", "cardio-gxt" ];
var counter = 0;
for (var i in checkboxes) {
if (this.getField(checkboxes).value!="Off") counter++;
}
if (counter < 1 ) event.value = "";
else event.value = counter + "C";
so I have only 2 questions:
1) Is it possible to iterate through a bunch of string values and select them based on the presence of a certain word?
2) Can I toggle the text field to hide (the one above which the script applies to), if the counter value is zero?
Thank you!
Yes, that will be it... To solve it, change this line:
if (f.name.indexOf("ultra") == 0) {
To:
if (f.type=="checkbox" && f.name.indexOf("ultra") == 0) {
Copy link to clipboard
Copied
1) Do you mean automatically process all the fields that contain a certain word in their names?
2) It's possible, sure, but why is hiding the field better then just resetting it?
Copy link to clipboard
Copied
1) yes, I would like the loop to look for specific words at the beginning of the string and if a match is found, to push that string into an array
2) resetting is one option that I don't mind but I was curious about hiding the field because I want the field to appear only when it is relevant for the user. But having the field remain blank is still an option, if hiding it proves to be too much of an issue or slows the form down.
Copy link to clipboard
Copied
1) This code will do that for you:
var fields = [];
for (var i=0; i<this.numFields; i++) {
var f = this.getField(this.getNthFieldName(i));
if (f==null) continue;
if (f.name.indexOf("some string")==0) {
fields.push(f.name);
}
}
2) You can use this code for that:
event.target.display = display.hidden;
(replace 'hidden' with 'visible' to revert it back)
Copy link to clipboard
Copied
Hey,
So I tried what you've put in for the code and now my code looks like this:
var fields = [];
for (var i=0; i<this.numFields; i++) {
var f = this.getField(this.getNthFieldName(i));
if (f==null) continue;
if (f.name.indexOf("ultra") == 0) {
fields.push(f.name);
}
}
var counter = 0;
for (var i in fields) {
if (this.getField(fields).value!="Off") counter++;
}
if (counter < 1 ) event.target.display = display.hidden;
else event.target.display = display.visible;
if (counter < 1 ) event.value = "";
else event.value = counter + "U";
The problem is that when I put this code in, the field displays " 1 U" even though I haven't checked anything off in that specific category. I do have ONE text field which is named "ultra-other" and is NOT a checkbox. Could this be affecting the loop?
The checkboxes I plan to target are strings which include the word ultra in them like "ultra-chest" or "ultra-thyroid" etc etc.
Not sure where to go from here :S
Copy link to clipboard
Copied
Yes, that will be it... To solve it, change this line:
if (f.name.indexOf("ultra") == 0) {
To:
if (f.type=="checkbox" && f.name.indexOf("ultra") == 0) {
Find more inspiration, events, and resources on the new Adobe Community
Explore Now