Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Subtract value from fixed number based on checkbox selections

Avatar

Level 3

Hi, I've looked everywhere in this forum and can't find the exact answer I'm after.

I have a numeric field that starts with a fixed value of '44', and 6 checkboxes. For each checkbox selected I want '2' subtracted from '44' e.g. if 1 checkbox is selected the value becomes '42' and if two checkboxes are selected the value becomes '40' and so on.

Is this possible? I'm going crazy trying to make this work.

Thanks for any help.

1 Accepted Solution

Avatar

Correct answer by
Level 7

Try this: Add code to the change event of the checkboxes

For example:

if (this.rawValue == "1") {

  this.resolveNode("numericField1").rawValue = this.resolveNode("numericField1").rawValue - 2;

}

if (this.rawValue == "0") {

  this.resolveNode("numericField1").rawValue = this.resolveNode("numericField1").rawValue + 2;

}

//the this.rawValue of 1 is a checked checkbox, 0 is unchecked. Using this code, a checked checkbox would subtract 2 from numericField1, and unchecked checkbox would add 2.

I had problems with this for a while because i had it in the click event not the change event.

View solution in original post

0 Replies

Avatar

Correct answer by
Level 7

Try this: Add code to the change event of the checkboxes

For example:

if (this.rawValue == "1") {

  this.resolveNode("numericField1").rawValue = this.resolveNode("numericField1").rawValue - 2;

}

if (this.rawValue == "0") {

  this.resolveNode("numericField1").rawValue = this.resolveNode("numericField1").rawValue + 2;

}

//the this.rawValue of 1 is a checked checkbox, 0 is unchecked. Using this code, a checked checkbox would subtract 2 from numericField1, and unchecked checkbox would add 2.

I had problems with this for a while because i had it in the click event not the change event.

Avatar

Level 3

That is brilliant! Thanks for that - worked perfectly!

Avatar

Level 7

Glad to help. This one stumped me at first.