Skip to main content
KRoss00
Participating Frequently
March 17, 2023
Question

Buttons (radio or other) and applying action (applying or removing discount)

  • March 17, 2023
  • 1 reply
  • 2148 views

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!

 

This topic has been closed for replies.

1 reply

Nesa Nurani
Community Expert
Community Expert
March 17, 2023

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.

KRoss00
KRoss00Author
Participating Frequently
March 17, 2023

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!

 

 

Nesa Nurani
Community Expert
Community Expert
March 17, 2023

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?