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

Calculation to add checkbox values and drop-down value

Community Beginner ,
Aug 29, 2020 Aug 29, 2020

Hi there!

 

I have a registration form when the user must select one of three check box options, each checkbox has a different export value. I also have one dropdown list with "yes" or "no" as options, "yes" needs to equal 0 and "no" needs to equal $45.00.

I have a text field where I want to calculate the checkbox option and add any "no"selection to it. 

I'm at a total loss and any help would be grealy appreciated.

 

Thanks!

TOPICS
Acrobat SDK and 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

correct answers 1 Correct answer

Community Beginner , Aug 31, 2020 Aug 31, 2020

Apologies for having not updated the thread sooner.

 

Yes, NessaNurani's solution worked beautifully! She was so gracious to further assist me via private message to better understand and learn how to replicate her solution myself, as I was having difficulty doing so.  She was able to help me identify where I was going wrong. 

 

A huge thanks to NessaNurani!

 

Cheers!

 

 

Translate
LEGEND ,
Aug 29, 2020 Aug 29, 2020

What exactly  is the role of the checkboxes?  You said you have three...what are the export values of each?

 

And what you're saying is, that when a user selects NO from the dropdown menu the texfield should take this string value plus the export value of whatever checkbox is checked?

 

 

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 ,
Aug 30, 2020 Aug 30, 2020

Try this:

var a = this.getField("checkbox1").value;
var b = this.getField("checkbox2").value;
var c = this.getField("checkbox3").value;
var x = this.getField("dropdown1").value;
if(a!="Off"){
event.value = a+x;}
else if(b!="Off"){
event.value = b+x;}
else if(c!="Off"){
event.value = c+x;}
else event.value = 0;

 

don't forget to add export values to yes and no in dropdown field.

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 Beginner ,
Aug 30, 2020 Aug 30, 2020

Hi there, I uploaded the example I'm working with if that's helpful:)

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 Beginner ,
Aug 30, 2020 Aug 30, 2020

Hi there, that's exactly right!

 

Checkbox 1 = $150.00

Checkbox 2 = $180

Checkbox 3 - $150

Dropdown List "Yes" = $0.00

Droption List "No" = $45.00

 

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 Beginner ,
Aug 30, 2020 Aug 30, 2020

Where do I copy and paste this script? Is it in the Text Field Properties of the fields I want to calculate the total amount under the "Calculate" tab - "Simplefied field notation"?

Thanks so mych for your help:)

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 ,
Aug 30, 2020 Aug 30, 2020

I update your file to make the code work let me know if you need anything else.

Registration Example update 

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 Beginner ,
Aug 30, 2020 Aug 30, 2020

Thank you so mych NesaNurani!!! 

I tried to replicate what you did and don't know what I'm doing wrong:( 

Last time promise bothring you I promoise...but could you take a look at this copy (CanSkate Skating Session - Updated Aug 29, 2020) and help me learn what I'm missing to get the field to calculate.

 

A huge 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
LEGEND ,
Aug 31, 2020 Aug 31, 2020

Hey Jennifer, 

 

Would you mind updating this thread.

 

Did the solution provided by NessaNurani resolved your issue?

 

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
Community Beginner ,
Aug 31, 2020 Aug 31, 2020
LATEST

Apologies for having not updated the thread sooner.

 

Yes, NessaNurani's solution worked beautifully! She was so gracious to further assist me via private message to better understand and learn how to replicate her solution myself, as I was having difficulty doing so.  She was able to help me identify where I was going wrong. 

 

A huge thanks to NessaNurani!

 

Cheers!

 

 

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
LEGEND ,
Aug 30, 2020 Aug 30, 2020

You can use something like this:

if (this.getField("myDropdown").valueAsString !="Off") {

if (this.getField("myDropDown").valueAsString =="yes") event.value = util.printf("$%.2f",  this.getField("myCheckBox").value);

else if (this.getField("myDropDown").valueAsString =="no") {

var a =  this.getField("myCheckBox").value+45.00;

event.value = util.printf("$%.2f",  a);
  }
}

if (this.getField("myCheckBox").value ="Off") event.value = "";

 

 

Place this script as the custom calculation script of the text field where you want these results to be output. 

 

 

See slide:

customcalculation.pngexpand image

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