Skip to main content
Known Participant
Apr 9, 2025 1:32 PM UTC
Answered

Insert numbers depending on which checkboxes are checked

This one has me stumped.  I have four checkboxes named A, B, C and D.  I also have a text field that is formatted for numbers.  Two of the four check boxes will alway be checked.  If I check the A checkbox and C checkbox OR the A checkbox and the D checkbox, I want the number 0 to appear in the Numbers text field.  If I check the B checkbox and the C checkbox, I want the number 500 to appear in the Numbers text field.  If I check the B checkbox and the D checkbox, I want the number 800 to appear in the Numbers text field.  Thanks for any help with this.

try67
try67Correct answer
Community Expert
Apr 9, 2025 1:45 PM UTC

You didn't specify what should happen if C and D are ticked... But at any rate, you can use this code for that:

 

var a = this.getField("A").valueAsString!="Off";
var b = this.getField("B").valueAsString!="Off";
var c = this.getField("C").valueAsString!="Off";
var d = this.getField("D").valueAsString!="Off";

if ((a && c) || (a && d)) event.value = 0;
else if (b && c) event.value = 500;
else if (b && d) event.value = 800;
else event.value = "";

3 replies

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
Apr 9, 2025 1:45 PM UTC

You didn't specify what should happen if C and D are ticked... But at any rate, you can use this code for that:

 

var a = this.getField("A").valueAsString!="Off";
var b = this.getField("B").valueAsString!="Off";
var c = this.getField("C").valueAsString!="Off";
var d = this.getField("D").valueAsString!="Off";

if ((a && c) || (a && d)) event.value = 0;
else if (b && c) event.value = 500;
else if (b && d) event.value = 800;
else event.value = "";
Translate
Known Participant
Apr 9, 2025 2:02 PM UTC

C and D would never both be ticked.  I'll give this a try and report back.  Thanks!

Translate