• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

New Here ,
Mar 16, 2023 Mar 16, 2023

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!

 

TOPICS
PDF forms

Views

1.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 16, 2023 Mar 16, 2023

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 16, 2023 Mar 16, 2023

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!

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 17, 2023 Mar 17, 2023

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 17, 2023 Mar 17, 2023

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 17, 2023 Mar 17, 2023

Copy link to clipboard

Copied

Ahh good point, the discount applies to orders over $400! If nothing is selected it should default to no.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 17, 2023 Mar 17, 2023

Copy link to clipboard

Copied

LATEST

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;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines