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

Linking a dollar value to a Check Box

Explorer ,
Mar 01, 2021 Mar 01, 2021

We are creating a pdf with a filable menu.  If the meal choice is checked it will be added to the total.  I want to link a dollar value to check box and the check box to a Text Field that totals the Check Boxes.  I also have 2 Radio Buttons that I need "turned on" if Check Box is selected.  

TOPICS
Create PDFs , Edit and convert PDFs , General troubleshooting , How to , JavaScript
2.0K
Translate
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
3 ACCEPTED SOLUTIONS
Community Expert ,
Mar 01, 2021 Mar 01, 2021

You need to set export value of checkboxes, set their export value to be the price you want except checkbox10,

also change "Radio button choice" to be price for that button and then use this script

as "Custom calculation script" of field "Total"

var total = 0;
var rb = 0;
if(this.getField("Check Box10").valueAsString != "Off" && this.getField("Banquet").valueAsString != "Off")
rb = Number(this.getField("Banquet").value);
for (var i=1; i<=9; i++) {
if (this.getField("Check Box"+i).valueAsString != "Off")
total += Number(this.getField("Check Box"+i).value);
}
event.value = total+rb;

 

View solution in original post

Translate
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 02, 2021 Mar 02, 2021

Ok, lets say you have checkbox named "PayPal"

If checkbox is checked it will add 4% fee

In the code I gave you replace just last line

event.value = total+rb;

with this:

if(this.getField("PayPal").valueAsString != "Off")
event.value = (total+rb)*1.04;
else event.value = total+rb;

 

View solution in original post

Translate
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 07, 2021 Mar 07, 2021

If you don't want confusion with rb and checkbox, as Mouse UP event of "Check Box10" use this:

if(event.target.value == "Off"){
this.getField("Banquet").display = display.hidden;
this.getField("Banquet").value = "Off";}
else this.getField("Banquet").display = display.visible;

This will hide radio buttons until checkbox is checked and reset them.

(for first time only set rb hidden manually or just check and uncheck checkbox)

View solution in original post

Translate
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 01, 2021 Mar 01, 2021

What are names of checkboxes and how many is there?

You want to set price as checkbox export value to be added to total if checkbox is checked?

What are conditions to turn radio buttons on , any checkbox checked will turn them or? their names?

Translate
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
Explorer ,
Mar 01, 2021 Mar 01, 2021

Check Box1, Check Box2, Check Box3....Check Box10  There are 10 checkboxes.

 

Yes, each Check Box is a meal and I would like the value of the checkmarked meal to be added to the total in the Text Field named TOTAL

 

Check Box10 is associated to text Awards Banquet

There are two Radio Buttons name Banquet with Radio Button Choice: Beef and Chicken (whickever Radio Button is chosen needs to become the value for the Banquet Check Box10 to be added to the TOTAL)

 

Meals.jpg

Translate
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 01, 2021 Mar 01, 2021

You need to set export value of checkboxes, set their export value to be the price you want except checkbox10,

also change "Radio button choice" to be price for that button and then use this script

as "Custom calculation script" of field "Total"

var total = 0;
var rb = 0;
if(this.getField("Check Box10").valueAsString != "Off" && this.getField("Banquet").valueAsString != "Off")
rb = Number(this.getField("Banquet").value);
for (var i=1; i<=9; i++) {
if (this.getField("Check Box"+i).valueAsString != "Off")
total += Number(this.getField("Check Box"+i).value);
}
event.value = total+rb;

 

Translate
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
Explorer ,
Mar 01, 2021 Mar 01, 2021

I am a complete novice and totally lost.  I appologize, I know what I want it to do but I'm not understanding how to make it do it.

Translate
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
Explorer ,
Mar 01, 2021 Mar 01, 2021

I finally managed to get it all entered correctly and It all works!  Thank you!!!

 

Only other question how would be... I would like it to add a 4% fee to the total if they choose to pay by PayPal.

Translate
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 02, 2021 Mar 02, 2021

Ok, lets say you have checkbox named "PayPal"

If checkbox is checked it will add 4% fee

In the code I gave you replace just last line

event.value = total+rb;

with this:

if(this.getField("PayPal").valueAsString != "Off")
event.value = (total+rb)*1.04;
else event.value = total+rb;

 

Translate
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
Explorer ,
Mar 07, 2021 Mar 07, 2021

That works perfect thank you!

 

How can I make the Radio Buttons for Chicken $50 (Banquet) or Beef $65 (Banquet) only active for selection if the Banquet (Check Box10) is Checked?  Also, one RB is always checked how can I make the uncheckable? 

 

Currently, the radio buttons each have an associated value that goes to the event total but does not get included if the banquet box is not checked.  So if they select a meal option but forget to check the banquet box then their total will be wrong.

Translate
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 07, 2021 Mar 07, 2021

If you don't want confusion with rb and checkbox, as Mouse UP event of "Check Box10" use this:

if(event.target.value == "Off"){
this.getField("Banquet").display = display.hidden;
this.getField("Banquet").value = "Off";}
else this.getField("Banquet").display = display.visible;

This will hide radio buttons until checkbox is checked and reset them.

(for first time only set rb hidden manually or just check and uncheck checkbox)

Translate
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
Explorer ,
Mar 07, 2021 Mar 07, 2021
LATEST

Thank you!

 

Translate
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