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

Help w/drop down menu's and calculations

Community Beginner ,
Aug 20, 2020 Aug 20, 2020

Copy link to clipboard

Copied

I'm creating a form for our company.  I have a set of drop down menu's with different services named Services 1 and so on.  With those, I have them set to export a value based on the selection and that goes to another drop down next to it, SA1.  SA1 is set for a  custom calculation script "event.value = this.getField("Services 1").valueAsString;". One of my selections requires a calcuation but I don't know how to do it automatically. For instance, in my first drop down "Services 1", I want one of the selections to multiply a number from another text field "Size" by 15 and have the total in SA1.  Is this possible? I can make the 2nd set of drop downs (SA1) a text field instead, it doesn't have to be another drop down.  

Thanks everyone

TOPICS
How to , PDF forms

Views

1.5K

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

correct answers 2 Correct answers

Community Expert , Aug 22, 2020 Aug 22, 2020

++++++CORRECTION TO MY REPLY WITH FEET + INCHES CALCULATION AND APOLOGIES FOR MY MISTAKE

 

 

I made a mistake and added an unnecessary (incorrect ) extra step in the caconversion of feet to inches of the "Total Size" field:

 

 

Use this as the custom calculation script of the "Total Size" field:

 

var f = ((this.getField("FT").value/.08333)+(this.getField("IN").value))/12;
event.value = util.printf("%,0.2f", f);

 

I mistakenly calulated inches to feet and was adding feet to inches to it. Your calculation

...

Votes

Translate

Translate
Community Expert , Aug 28, 2020 Aug 28, 2020

Combine it like this:

 

if (event.name&&event.source.name =="Services 2") {

event.value =  this.getField("Services 2").value;

if (this.getField("Services 2").valueAsString == "Shrink Wrap") event.value = util.printf("$%,0.2f", (this.getField("Total Size").value * 15));

else if (this.getField("Services 2").valueAsString == "Shrink Wrap Wide") event.value = util.printf("$%,0.2f", (this.getField("Total Size").value * 17));

}

 

Copy and paste the code in all of the calculataed "SA" fields..  An

...

Votes

Translate

Translate
Community Expert ,
Aug 20, 2020 Aug 20, 2020

Copy link to clipboard

Copied

+++EDITED REPLY,  I made an error and didn't inlcude a second part to the original reply.

 

Yes that is possible. 

 

You need to include a condition with (IF /ELSE ) statement(s) in your custom calculation script in order  to perform the appropraite multiplication when the desired selection is made at "Selection 1" dropdown.

 

It would look something similar to this and this will only get the face value of the "Services 1" dropdown menu:

 

 

 

if (this.getField("Services 1").valueAsString=="mySelection") {
event.value = this.getField("myOtherField").value * 15;
}

else event.value = this.getField("Services 1").valueAsString;


 

 

Now, be advised that when you use "valueAsString' to get a value from a dropdown menu it will not get the export values that you've assigned for each listed item.  Using the get method for a valueAsString will only get the face value of the selected item (the value as it appears to the user), not the export value.

 

If you really need to work with the export value of a a listed item that was selected from a dropdown menu, you'll need to modify the script above similar to this:

 

 

if (this.getField("Services 1").valueAsString =="mySelection") {

var f = this.getField("Services 1").currentValueIndices;
if (typeof f == "number") event.value = f.getItemAt(a,true)*15;
}
else event.value = this.getField("Services 1").valueAsString;

 

 

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

Copy link to clipboard

Copied

Thanks for your help.  I wasn't able to get either to work for me, but I don't know how to edit the 2nd.  In my first drop down I have the list of services we offer.  Everything has a set price except one item, Shrink Wrap.  This is the one I'm having trouble with because it's based off another value "TotalSize" mutiplied by 15.  There is a set of drop downs next to the first set with prices listed for the corresponding services.  I did it this way at first because I didn't know how the export values worked. 

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

Copy link to clipboard

Copied

If I got it right you want to give "Shrink Wrap" value from "TotalSize"*15?

If yes then you can try incorporate this into your calculations:

var a = this.getField("TotalSize").value;
var b = this.getField("SA1").value;
var x = a*15;
if(b == "Shrink Wrap"){
event.value = x;
}

Or if you still have issue try sharing your file so we can see whats going on.

 

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

Copy link to clipboard

Copied

I wasn't able to make that work, but I really don't know what I'm doing.  I'm definately learing as I go so thank you for your help.  Here is a google drive link to what I'm working on.  Up top is length in feet and inches, covereted to a decimal in "TotalSize".  I added Shrink Wrap to Services 2.  I'll have it in every drop down 2-10.  

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

Copy link to clipboard

Copied

+++ EDITED REPLY, CHANGES  AND DELETION OF THE BULLET BELOW (in bold), CORRECTED SPECIFICALLY  THIS PART    240.009600384 + .8333 (which is wrong and unnecessary verbage):

 

  • Now you can add up all the inches : 240.009600384 + .8333 = 240.842900384

    If you round up decimal to only two integers to the right of the decimal period  it equals 240.84

    Now we can convert to feet accurately. Which is 240.84 divided by 12 inches = 20.07 feet.

    Can you see what I mean?   Now you can round up the total propperly.

    Precission in calculations is important. Some customers can pick up on this very quickly and can tell if something is wrong.

 

 

When converting inches to feet the ratio  is:

  • 1 inch = .08333 feet   (and 1 foot = 12 inches)

 

If you convert inches to feet in your example it would be:

  • 10 inches multiplied by .08333  equals to .8333  or   .83 (rounded up).

 

While If you convert 20 feet to inches:

  • 20 feet * 12 = 240 inches  (or, also expressed as: 20 / .08333 = 240.009600384)

 

Now, I prefer to use  convert feet to inches then add to the remaining value of the "IN" (inches) field which is a lot cleaner from a human-readable calculation point of view:

  • 20 ft * 12 inches = 240 inches
  • 240" + 10" = 250"
  • 250"  divided by 12" per feet = 20.83    (so you're absolutely correct) 

 

Using util.printf() method we can assign the proper format for the "Total Size" field value. 

 

 

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

Copy link to clipboard

Copied

++ EDITED REPLY,  corrected error in feet+inches calculation,, updated the calculation correction in the shared PDF.

 

So I found why none of the suggestions were working on your end.

 

  • Up top is length in feet and inches, covereted to a decimal in "TotalSize".

 

The name of your total size field you had it spelled wrong.

 

There is actually a space between the word Total and Space: "Total Size".

 

Field names must match the exact spelling and use of upper or lower case, otherwise  your  calculated fields won't work.

 

Besides this observation, I developed the correct calculation script to convert feet to inches and inches to feet for the "Total Size" field.

 

Use this as the custom calculation script of the "Total Size" field:

 

 

 

var f = ((this.getField("FT").value/.08333)+(this.getField("IN").value))/12;
event.value = util.printf("%,0.2f", f);

 

 

 

And use this in the "SA2" field custom calculation script:

 

 

 

event.value =  this.getField("Services 2").value;

if (this.getField("Services 2").valueAsString == "Shrink Wrap") event.value = util.printf("$%,0.2f", (this.getField("Total Size").value * 15));

 

 

 

To see your fixed PDF in action click here: test-SHRINK WRAP PROBLEM FIXED 

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

Copy link to clipboard

Copied

++++++CORRECTION TO MY REPLY WITH FEET + INCHES CALCULATION AND APOLOGIES FOR MY MISTAKE

 

 

I made a mistake and added an unnecessary (incorrect ) extra step in the caconversion of feet to inches of the "Total Size" field:

 

 

Use this as the custom calculation script of the "Total Size" field:

 

var f = ((this.getField("FT").value/.08333)+(this.getField("IN").value))/12;
event.value = util.printf("%,0.2f", f);

 

I mistakenly calulated inches to feet and was adding feet to inches to it. Your calculation was correct. I apologize for the eay I expressed my self earlier about this.  I guess I was loving too much  reading to myself and lecturing myself.  Once again, I  apologize.

 

Anyway, I hope this helps.

 

 

I also updated the file link above in my earlier reply.

 

 

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

Copy link to clipboard

Copied

That worked perfectly, thank you very much.  Since you seem to be really good at this, do you mind helping with one other thing?  Is there a way to get the drop downs to scroll with the mouse scroll wheel?

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
Enthusiast ,
Aug 24, 2020 Aug 24, 2020

Copy link to clipboard

Copied

I don't think that you can do that.

If you have really long list open dropdown and start typing ( if you know what you searching for).

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

Copy link to clipboard

Copied

That's what I was figuring out.  Typing it works, except it's really picky about capitalization!  

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

Copy link to clipboard

Copied

Can you help me with the custom calculation script a little more?  Sometimes I enter in custom text and then in the amount field I select TBD or WTY.  With this current calculation it enters the same thing thats typed in the services drop down. I can resolve this by changing it to not calculate that field but I'm the only one that can do that.

 

Thanks!!

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
Enthusiast ,
Aug 26, 2020 Aug 26, 2020

Copy link to clipboard

Copied

Why do you even need dropdown fields in amount? 

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

Copy link to clipboard

Copied

Good catch!. I noticed the same. 

 

The user wants to have the ability to manually select from those options a non-numeric value though.

 

If a user types in a different item instead of selecting one of the listed options in the "Services" dropdown menu, they should have the ability to select TBD or WTY from that "SA" amount dropdown lists.

 

I am thinking the best approach is to use something like this, for example:

 

if (event.name&&event.source.name =="Services 6") {

event.value = this.getField("Services 6").valueAsString;

}

 

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

Copy link to clipboard

Copied

ls_rbls,  I wasn't able to implement that.  Where would I combine it with the other formula for the SA fields?  We have this already

"

event.value = this.getField("Services 2").value;


if (this.getField("Services 2").valueAsString == "Shrink Wrap") event.value = util.printf("$%,0.2f", (this.getField("Total Size").value * 15));
if (this.getField("Services 2").valueAsString == "Shrink Wrap Wide") event.value =
util.printf("$%,0.2f", (this.getField("Total Size").value * 17));

"

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

Copy link to clipboard

Copied

Combine it like this:

 

if (event.name&&event.source.name =="Services 2") {

event.value =  this.getField("Services 2").value;

if (this.getField("Services 2").valueAsString == "Shrink Wrap") event.value = util.printf("$%,0.2f", (this.getField("Total Size").value * 15));

else if (this.getField("Services 2").valueAsString == "Shrink Wrap Wide") event.value = util.printf("$%,0.2f", (this.getField("Total Size").value * 17));

}

 

Copy and paste the code in all of the calculataed "SA" fields..  And don't forget to change the number in the "Services 2"  to the corresponding "Services" field number

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

Copy link to clipboard

Copied

LATEST

Fantastic.  I really appreciate your help with this, thank you so much!

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

Copy link to clipboard

Copied

I did it originally because I didn't know how to make the first selection output a value, so I selected the values manually.  I still need it though, because I may add a service that is not in the drop down menu, like a seat repair.  In the next field it would be TBD for the amount or WTY for warranty.  Maybe not the best way to do it, but it's been a work in progress and I had to hand write these things before, hundreds a year with rhuematoid arthritis.  Wasn't easy.  This is MUCH easier.  

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