Copy link to clipboard
Copied
I am trying to write calculation for when a checkbox is selected a fee will calculate based on "Subtotal" and "Tax" boxes multiplied by .035
So if Checbox7 is selected (Subtotal + Tax) * .035
This is what I ended up using. : answer came from try67. event.value = (this.getField("Checkbox7").valueAsString=="Off") ? 0 : (Number(this.getField("Subtotal").valueAsString) + Number(this.getField("Tax").valueAsString)) * .035;
Copy link to clipboard
Copied
I am trying to write calculation for when a checkbox is selected a fee will calculate based on "Subtotal" and "Tax" boxes multiplied by .035
So if Checbox7 is selected (Subtotal + Tax) * .035
This is what I ended up using. : answer came from try67. event.value = (this.getField("Checkbox7").valueAsString=="Off") ? 0 : (Number(this.getField("Subtotal").valueAsString) + Number(this.getField("Tax").valueAsString)) * .035;
Copy link to clipboard
Copied
Assuming SubTotal is calculated in a SubTotal field using a sum calculation applied to the SubTotal field that adds a number of number fields.
And assuming the tax is calculated as a percentage of the subtotal or a number entered into a Tax Field. I used a flat percentage based on location tax rates.
Try the following by creating a mouse up javascript assigned to the checkbox:
//------------------------------------------------------
var st = this.getField("SubTotal").value;
var tax = this.getField("Tax").value;
var total = this.getField("Total").value;
if (event.target.value == "Yes") { // This is the checkbox
total = (st+tax)*1.035;
} else {
total = st+tax;
}
this.getField("Total").value = total;
//-------------------------------------------------------
I've tested this and it works for me.
Copy link to clipboard
Copied
You may want to implement an IF /ELSE condition with your checkbox.
You can use something like this:
if (this.getField("Checbox7").value =="Yes"){
event.value = (this.getField("Subtotal").value+ this.getField("Tax").value)*.035;
}
else if (this.getField("Checbox7).value =="Off"){
event.value = this.getField("Subtotal").value + this.getField("Tax").value;
}
You can use this script as the custom calculation script of your Total field, for example.
Copy link to clipboard
Copied
There are several ways to skin this cat. No else if is needed. It either == "Yes" or it doesn't. I used event.target.value since I was applying the mouse up action to the checkbox.
Copy link to clipboard
Copied
You just contradicted yourself.
Your line of code above is actually using an IF and ELSE statement...
So, I don't know what you're talking about.
Copy link to clipboard
Copied
Read my reply again. No self contradiction.
Your code has an "ELSE IF" statement. I stated that an "ELSE IF" was not needed. Yes, my code is using an "using an IF and ELSE statement...", but it DOESN'T use an "ESLE IF" statement.
Copy link to clipboard
Copied
Good catch!
I wasn't looking at my typo.
Now I feel like an idiot.
Thank you for spotting that.
Copy link to clipboard
Copied
Nah, don't sweat it! I look like an idiot all the time! We all come here to ask for help and to offer help. That's what's important.
Have a great Day!
Copy link to clipboard
Copied
This is what I ended up using. : answer came from try67. event.value = (this.getField("Checkbox7").valueAsString=="Off") ? 0 : (Number(this.getField("Subtotal").valueAsString) + Number(this.getField("Tax").valueAsString)) * .035;