Copy link to clipboard
Copied
I'm trying to make a button on either side of a row of 20 checkboxes that, when pressed, will either increase or decrease the checked boxes in sequence by 1 (ie: Pressing the "+" button would increase the number of checked boxes from 0 to 1, 1 to 2, etc). As well, I have a separate counter (text field) that would gain or lose a number respectively with each button press (ie: Pressing the button does the above function, but also increases the counter from 0 to 1, or decreases from 1 to 0, etc).
I think I have an idea of how it might be done, but i'm not familiar enough with grouping commands to know if it can be done in sequence like that - without putting in repeated lines of "look at each individual box and see which is active". (If it comes to that, it comes to that).
Here's what I think i'd have to do for each checkbox to get it to read their state:
if (this.getField("Damage 1").value !="Off")
this.getField("Damage 1").checkThisBox(0,false) {
} else {
this.getField("Damage 1").checkThisBox(0,true)
}
There is something wrong with the field.
You have two option:
1. Delete field and create new one.
2.Create new field and give it same name and hide it, and put scripts in that field.
Here is file where I implement option 2 (I had to choose option 2 because I don't have that font) for you to test it:
https://drive.google.com/uc?export=download&id=1_Srszw4lPm0z6QL4yFF0GSnYcSVlaqqk
If you want field to be empty if it's 0 use this as validation script:
if(event.value==0)event.value="";
I did that i
...Copy link to clipboard
Copied
I assume your checkboxes are named "Damage 1-20" and text field is named "counter", if not, rename fields, you can use this:
At '+' button Action tab -> Mouse UP -> Run a JavaScript
for(var i=1; i<=20; i++){
if(this.getField("Damage "+i).valueAsString == "Off"){
this.getField("Damage "+i).checkThisBox(0,true);
this.getField("counter").value += 1;
break;}}
At '-' button Action tab -> Mouse UP -> Run a JavaScript
for(var i=20; i>=1; i--){
if(this.getField("Damage "+i).valueAsString != "Off"){
this.getField("Damage "+i).checkThisBox(0,false);
this.getField("counter").value -= 1;
break;}}
Copy link to clipboard
Copied
This worked like a charm! However, now that i've got the counter's font set up, i've run into another snag: the way it's set, I'd like leading 0's in front of all single digits. Right now it only displays, for example, "1, 2, 3, etc", when i'd like it to display "01, 02, 03, etc" when it adds to it. Otherwise the code works splendidly, I can't thank you enough for your help!
Copy link to clipboard
Copied
At "counter" field properties -> format tab -> custom -> as custom format script use this:
if(event.value){
if(event.value.length == 1 && event.value != 0)
event.value = "0"+event.value;}
Copy link to clipboard
Copied
Sorry for the late reply - I was out for the weekend - but that custom formatting doesn't seem to stay. I put in the code on that page, but it doesn't display it and is blank when I go back into it. I'm unsure if this is an issue overall or just with this text field.
Copy link to clipboard
Copied
Can you share your file?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
There is something wrong with the field.
You have two option:
1. Delete field and create new one.
2.Create new field and give it same name and hide it, and put scripts in that field.
Here is file where I implement option 2 (I had to choose option 2 because I don't have that font) for you to test it:
https://drive.google.com/uc?export=download&id=1_Srszw4lPm0z6QL4yFF0GSnYcSVlaqqk
If you want field to be empty if it's 0 use this as validation script:
if(event.value==0)event.value="";
I did that in test file.
Copy link to clipboard
Copied
I had figured something was up with it. That's excellent, I really do appreciate the help with this! It turned out to be a bit more complicated than I was expecting, haha. Many thanks!