Skip to main content
Participant
September 8, 2021
Answered

Checkboxes cannot be unchecked when used in JavaScript Calculation

  • September 8, 2021
  • 1 reply
  • 634 views

Hello everyone,

 

I have got a problem with checkboxes which are used to calculate the value of a field with a few lines of JavaScript code. This is the code I am using at the moment (I set the output values of the checkboxes to 1):

 

if (getField("Checkbox1").value = 1){
     if(getField("Checkbox2").value = 1){
     if(getField("Checkbox3").value = 1){
     this.getField("Calculation").value = 1.1

     }

     }

}

 

After that I want to set the value to 1.0 if only 2 boxes are checked and then to 0.9 when only one is checked.

 

The calculation works fine but if I try to uncheck a checkbox after the calculation it will always re-check it as soon as I input another number in a random other field on the document. So I open the document and check all 3 boxes; calculation of value 1.1 works fine; I uncheck one of the boxes; input a number somewhere else on the document and the formerly unchecked box is now checked again without me doing it.

 

Can anyone help with this issue?

This topic has been closed for replies.
Correct answer Bernd Alheit

To compare values you must use ==, not only =

E.g.:

if (getField("Checkbox1").value == 1){

1 reply

Bernd Alheit
Community Expert
Bernd AlheitCommunity ExpertCorrect answer
Community Expert
September 8, 2021

To compare values you must use ==, not only =

E.g.:

if (getField("Checkbox1").value == 1){

Max5C9FAuthor
Participant
September 8, 2021

Vielen Dank Bernd!