Skip to main content
Participant
August 7, 2021
Answered

How to write script so that when checkbox is checked, a subtraction is completed

  • August 7, 2021
  • 1 reply
  • 634 views

Hello,

 

I am making a somewhat follow-up post to my previous one involving the same form from that last post. Here is the link to that question.

 

What I am trying to do now is there is a checkbox next to my Site Assessment. I want it so that when the checkbox is checked, the site assessment gets subtracted from the total. I've tried a few different code options and it still doesn't want to compute for me.

 

Here is a sample of what I wrote:

// if Assessment Paid box is checked, subtract assessment from RequiredTotal

if (this.getField("Assessment Paid").value != "Off")Number(this.getField("RequiredTotal").value) - Number(this.getField("Required").value);

 

Any help would be greatly appreciated, thanks in advance!

This topic has been closed for replies.
Correct answer Nesa Nurani

You didn't include where to show result of substraction. if you want to show result in field where you put calculation use event.value, something like this:

if (this.getField("Assessment Paid").value != "Off")

event.value = Number(this.getField("RequiredTotal").value) - Number(this.getField("Required").value);

 

1 reply

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
August 7, 2021

You didn't include where to show result of substraction. if you want to show result in field where you put calculation use event.value, something like this:

if (this.getField("Assessment Paid").value != "Off")

event.value = Number(this.getField("RequiredTotal").value) - Number(this.getField("Required").value);

 

Participant
August 7, 2021

Worked like a charm, thanks!