Skip to main content
tobymacdonald
Inspiring
September 29, 2016
Answered

Conditional formula based on Multiple Checkbox?

  • September 29, 2016
  • 1 reply
  • 1933 views

Warning: Newbie here and appreciate your patience...

Trying to write a custom calculation based on 2 different checkboxes (CleanOverride & AdvRentDeposit). I might be going about this all wrong, but these checkboxes currently show/hide a calculated value or a user submitted value. The calculation below is aimed at showing the final monies owed (Total - Varying Advanced Deposits). Here's where I landed, but not having any luck...any help is much appreciatated!

(function () { 

var v1 = getField(“TotalDue”).value - getField("Security Deposit").value - getField(“Pet Deposit”).value - getField(“AdvRent”).value - getField(“AssAppFee”).value;

var v2 = getField(“TotalDue”).value - getField("Security Deposit").value - getField(“Pet Deposit”).value - getField(“AdvRentAlt”).value - getField(“AssAppFee”).value;

var v3 = getField(“TotalDueAlt”).value - getField("Security Deposit").value - getField(“Pet Deposit”).value - getField(“AdvRent”).value - getField(“AssAppFee”).value;

var v4 = getField(“TotalDueAlt”).value - getField("Security Deposit").value - getField(“Pet Deposit”).value - getField(“AdvRentAlt”).value - getField(“AssAppFee”).value;

if ((getField("CleanOverride").value !== "On")&&(getField("AdvRentDeposit").value !== "On"))  { 

        event.value = v4; 

    } else if ((getField("CleanOverride").value !== "On")&&(getField("AdvRentDeposit").value !== "Off"))  { 

        event.value = v3;

    } else if ((getField("CleanOverride").value !== "Off")&&(getField("AdvRentDeposit").value !== "On"))  { 

        event.value = v2;

    } else if ((getField("CleanOverride").value !== "Off")&&(getField("AdvRentDeposit").value !== "Off"))  { 

        event.value = v1; 

    } else {

        event.value = "Error"; 

    } 

 

})(); 

This topic has been closed for replies.
Correct answer tobymacdonald

I'm not seeing any error messages in the file you attached and the calculation works (well, the field's value is updated, I didn't check to see if the results are actually correct).


The values were not correct. I scrapped the whole thing and went to a different way of checking the checkboxes and it now works. Here's the final custom calculation for reference:

var x = this.getField("AdvRentDeposit");

var y = this.getField("CleanOverride");

if (x.isBoxChecked(0))

var x = getField("Rent").value - getField("AdvRentAlt").value;

else

var x = getField("Rent").value - getField("AdvRent").value;

if (y.isBoxChecked(0))

var y = getField("HideClean").value + getField("StateTaxCleanAlt").value + getField("CtyTaxCleanAlt").value;

else

var y = getField("CleaningFee").value + getField("StateTaxClean").value + getField("CtyTaxClean").value;

event.value = x + y + getField("StateTaxRent").value + getField("CtyTaxRent").value

1 reply

try67
Community Expert
Community Expert
September 29, 2016

What exactly is the issue? Is the code not running at all (if not, what error messages do you see in the JS Console)? Or is it returning the wrong results? Please clarify.

First issue I'm seeing with it is that you're using non-standard quotes in some of the first lines of the code. You need to only use straight single (') or double (") quotes. Make sure you're writing the code in a plain-text editor and not in something like Word, to avoid such issues.

tobymacdonald
Inspiring
October 3, 2016

Thank you for the response! I did edit this in Word and made the corrections; will do so in a plain-text editor moving forward (thanks for the hint!).

There is no error that comes up, but the calculation doesn't change as I select the checkboxes. I double checked the calculation order,  but it doesn't appear to be anything there....not sure where I'm off....appreciate the help!

try67
Community Expert
Community Expert
October 3, 2016

Did you change the default export values of your check-boxes to "On"? Because by default it is "Yes"...