Copy link to clipboard
Copied
Hello world,
I have a problem with a form I'm trying to put together; the form will be used to tally the amount of trucks coming into a job site (I.E. it is a grid with checkbox items that are ticked as trucks come in). The problem is, I'd also like to add the option of having a textbox with a value that will automatically tick the right amount of checkbox items, rather than checking them all one by one.
I guess in summary the code would need to be like this: inputs > 0, Check Box 1 is checked. inputs > 1, Check Box 2 is checked, etc.
I have no real experience with javascript, so any help would be appreciated,
Thanks,
1 Correct answer
So basically you want to reset the entire set of fields, and then only tick those that were entered in the text field, right?
In that case, you can use this code, assuming you have fields named "Check Box 1" to "Check Box 10":
if (event.value) {
for (var i=1; i<=10; i++) {this.getField("Check Box " + i).checkThisBox(0, (i<=Number(event.value)));
}
}
Copy link to clipboard
Copied
Are your fields named "Check Box 1", "Check Box 2", etc.?
Copy link to clipboard
Copied
Also, what should happen if some check-boxes are already ticked? Should it reset all of them before ticking the amount entered? Should it add the pre-ticked ones? etc.
Copy link to clipboard
Copied
"Are your fields named "Check Box 1", "Check Box 2", etc.?"
The initial fields are named: Check Box 1, Check Box 2, Check Box 3. More field will be added and will probably follow the pattern of Check Box 1a, Check Box 1b, Check Box 1c, etc.
"Also, what should happen if some check-boxes are already ticked? Should it reset all of them before ticking the amount entered? Should it add the pre-ticked ones? etc."
No, I'm going to add a reset button for each row, so if two check boxes are checked before a number is punched in, they should conceivably stay checked.
Copy link to clipboard
Copied
That's not a very good naming scheme. I would recommend to use numbers only, unless there's a very good reason to do it differently.
I didn't quite follow the second answer. Let's say you have 10 check-boxes and 1-6 are ticked. The user enters "5" into the text box. What should happen?
Copy link to clipboard
Copied
"That's not a very good naming scheme. I would recommend to use numbers only, unless there's a very good reason to do it differently.
I didn't quite follow the second answer. Let's say you have 10 check-boxes and 1-6 are ticked. The user enters "5" into the text box. What should happen?"
Okay, I see what you're getting at, in that situation the 6th check box should not be checked; if it could be worked in to un-checked that 6th box, then I would prefer that.
I can change the naming scheme, its really on there only as a default for each box.
Copy link to clipboard
Copied
So basically you want to reset the entire set of fields, and then only tick those that were entered in the text field, right?
In that case, you can use this code, assuming you have fields named "Check Box 1" to "Check Box 10":
if (event.value) {
for (var i=1; i<=10; i++) {this.getField("Check Box " + i).checkThisBox(0, (i<=Number(event.value)));
}
}
Copy link to clipboard
Copied
Forgot to mention above, the code should be used as the custom validation script of the text field where the user enters the number of boxes to tick.
Copy link to clipboard
Copied
"So basically you want to reset the entire set of fields, and then only tick those that were entered in the text field, right?
In that case, you can use this code, assuming you have fields named "Check Box 1" to "Check Box 10":"
"Forgot to mention above, the code should be used as the custom validation script of the text field where the user enters the number of boxes to tick."
Got it, tried it, works; thank you try67.

