Copy link to clipboard
Copied
Hi all, I'm extremely new to this and it's generally outside of my wheelhouse so I'm looking for a bit of help. I'm hoping to create a budget form that allows people to select whether or not the item will be charged Harmonized Sales Tax (which is 13% where I'm from). Not all items are taxed so I'm allowing them to choose via a radio buttom whether tax is applicable. I'd like if they choose 'Y' the subtotal should calculate the 13% tax, and if they choose 'N' I'd want it to simply calculate based on the Cost Per and Quantity of the item.
I'm able to calculate the Quantity and Cost per into a subtotal very easily obviously, but I'm somewhat lost as to how I can use the radio buttons to calculate the percentage tax. Any help is much appreciated.
Copy link to clipboard
Copied
Hi,
This is an old thread that seems like it fell through the cracks. I hope by now you were able to figure it out.
If not, here are a few ideas:
var a = this.getField("radioButton").value;
var c = this.getField("Cost per Item").value;
var d = this.getField("Cost per Quantity").value;
if (a != "Y") event.value = c+d;
if (a != "N") event.value = (Math.ceil(c+d)*(13/100))+(c+d);
if ( (c =="") || (d =="") ) event.value ="";
Copy link to clipboard
Copied
I would reconsider the way this code is built. For starters, why check a negative condition when you can use the positive? It's just more confusing. Also, I would use an if-else if-else construction, instead of separate if-commands. That way there would be a default value used for the field, in case none of the conditions is met.
Copy link to clipboard
Copied
I tried the IF , ELSE conditions but with my current knowledge it was throwing back undesirable results. I 'm sure I wasn't following appropriate guidance.
Would you mind sharing an example?
Copy link to clipboard
Copied
I feel really dumb. Sometimes I really struggle understanding what people mean when they write.
So here it is:
var a = this.getField("radioButton").value;
var c = this.getField("Cost per Item").value;
var d = this.getField("Cost per Quantity").value;
if (a === "N") event.value = c+d;
else if (a === "Y") event.value = (Math.ceil(c+d)*(13/100))+(c+d);
else if ( (c =="") || (d =="") ) event.value ="";
This also works:
var a = this.getField("radioButton").value;
var c = this.getField("Cost per Item").value;
var d = this.getField("Cost per Quantity").value;
if (a === "N") {event.value = c+d;
} else {
if (a === "Y") { event.value = (Math.ceil(c+d)*(13/100))+(c+d);
} else {
if ( (c =="") || (d =="") ) event.value ="";
}
}
Thank you for continued mentoring. You're a beast!
Copy link to clipboard
Copied
Don't sweat it. It's a learning curve and you're doing pretty well.
I prefer the first code you posted. However, I would suggest you think of the following scenario: What will happen if none of those conditions is met? ie, a is neither "N" or "Y", and both c and d are not empty. What value will be assigned to the field then?
Copy link to clipboard
Copied
Ok this is what is working on my end:
var a = this.getField("radioButton").value;
var c = this.getField("Cost per Item").value;
var d = this.getField("Cost per Quantity").value;
if ( (a === "N") && (c && d !="") )event.value = c+d;
else if( (a === "Y") && (c && d !="") ) event.value = (Math.ceil(c+d)*(13/100))+(c+d);
else if ( ( a === "Y") || (a === "N") && (c || d =="") ) event.value ="";
else if ( ( a === "Y") || (a === "N") && (c && d =="") )event.value ="";
I'm gonna try JR's method.
Copy link to clipboard
Copied
Change the last line to just:
else event.value ="";
That covers all other situations.
Copy link to clipboard
Copied
great! thanks.
Copy link to clipboard
Copied
Use "1" as the export value for the "No" button, and use "1.13" as the export value for the "Yes" button.
So you just have to multiply the field "Quantity" by thefield "Cost per" by the button value.
This does not requires JavaScript.
Copy link to clipboard
Copied
This is with JR's suggestion:
var a = this.getField("radioButton").value;
var c = this.getField("Cost per Item").value;
var d = this.getField("Cost per Quantity").value;
if ( (a == "1") && (c && d !="") )event.value = c+d;
else if( (a == ".13") && (c && d !="") ) event.value = (Math.ceil(c+d)*(a))+(c+d);
else if ( ( a === ".13") || (a === "1") && (c || d =="") ) event.value ="";
else event.value ="";
Copy link to clipboard
Copied
"Zero", "Off" and "empty" values are automatically managed by Acrobat's buit in calculations
Copy link to clipboard
Copied
Thank you!
Copy link to clipboard
Copied
Tip: a set of radiobuttons cannot return "Off" if you tick one as default.
Copy link to clipboard
Copied
Awesome! thanks for that tip.