Subtract value from fixed number based on checkbox selections

Avatar

Avatar

stephenf8734174

Avatar

stephenf8734174

stephenf8734174

30-03-2016

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.

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

MinusZero

Avatar

MinusZero

MinusZero

30-03-2016

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.

Answers (2)

Answers (2)

Avatar

Avatar

MinusZero

Avatar

MinusZero

MinusZero

30-03-2016

Glad to help. This one stumped me at first.

Avatar

Avatar

stephenf8734174

Avatar

stephenf8734174

stephenf8734174

30-03-2016

That is brilliant! Thanks for that - worked perfectly!