Skip to main content
Known Participant
April 9, 2025
Answered

Insert numbers depending on which checkboxes are checked

  • April 9, 2025
  • 1 reply
  • 376 views

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.

Correct answer try67

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 = "";

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
April 9, 2025

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 = "";
Known Participant
April 9, 2025

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