Copy link to clipboard
Copied
Hey there, I have a form that applies a discount to certain audiences ā in this case if they are a subscriber. I wanted to use a check box (currently using a radio check box with the same name so only one can be selected).
I want the form to work that if the user selects 'No' the discount field (which is curently calculating discount based on order) to be $0.
Ive attached a screen shot to help illustrate what I am doing š
Didscount field is 'TextField104' and Radio button is 'Radio Buttton 1'
Any help woudl be greatly appreciated!
Copy link to clipboard
Copied
As custom calculation script of discount field use this:
if(this.getField("Radio Buttton 1").valueAsString == "No")
event.value = 0;
else{
//put here your original calculation for discount
};
You can also change 'else' to check if radio button is "Yes" if you wish to show discount only when "Yes" is selected.
Copy link to clipboard
Copied
Thank you so much for your help, so it would be:
if(this.getField("Radio Buttton 1").valueAsString == "No") event.value = 0; else{ // var nSubTotal = this.getField("TextField15").value; if( nSubTotal > 400) event.value = nSubTotal * 0.10; if( nSubTotal < 400) event.value = nSubTotal = 0; };
I must have something not quite right, its not calculating. Probably a silly question, but do I need to do something to specify what is a Yes or No button? Sorry, im slowly learning!
Copy link to clipboard
Copied
Try this:
if(this.getField("Radio Buttton 1").valueAsString == "No")
event.value = 0;
else{
var nSubTotal = Number(this.getField("TextField15").valueAsString);
if( nSubTotal > 400) event.value = nSubTotal * 0.10;
else if( nSubTotal < 400) event.value = 0;}
Do you wish to calculate discount only if "Yes" is selected?
What should happen if value is exactly 400?
Copy link to clipboard
Copied
Are you sure you've set the Export Values of the radio-buttons to Yes and No?
Also, what should happen if neither option is selected? Isn't that just the same as No?
Copy link to clipboard
Copied
Ahh good point, the discount applies to orders over $400! If nothing is selected it should default to no.
Copy link to clipboard
Copied
So you want to calculate discount only if "Yes" is selected and value is over 400 otherwise it should show 0?
In that case, use this:
var RB = this.getField("Radio Buttton 1").valueAsString;
var nSubTotal = Number(this.getField("TextField15").valueAsString);
event.value = RB == "Yes" && nSubTotal > 400 ? nSubTotal * 0.10 : 0;