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

How do you writh a javascript for percentage of discount mutiply by quantity and cost.

New Here ,
Mar 17, 2017 Mar 17, 2017

How do I calculate the quantity (2) by the cost ($10) and (discount)?  For example, (2*$10.00)*(1-15%)

TOPICS
Acrobat SDK and JavaScript
555
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 18, 2017 Mar 18, 2017

What are the names of the fields involved?

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
New Here ,
Mar 18, 2017 Mar 18, 2017

Quantity

Cost

Discount

Total Cost

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 18, 2017 Mar 18, 2017

Is the Discount field a percentage field, or a number 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
New Here ,
Mar 18, 2017 Mar 18, 2017

I have attached the form for you to review. I would like to be able to enter 15 in the discount column and it convert to 15%. I would like for the “Total Cost” column to calculate the “Quantity” * “Cost for 1” * “Discount”.

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 18, 2017 Mar 18, 2017

You can't attach files here, only post a link to a file-sharing site.

If you want the user to enter "15" and have it show up as "15%" you would need to use custom keystroke and format scripts.

Let's say you've done that. The calculation code for the Total Cost field will then be:

var qty = Number(this.getField("Quantity").value);

var cost = Number(this.getField("Cost for 1").value);

var discount = Number(this.getField("Discount").value);

event.value = (qty*cost) * (1-(discount/100));

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
New Here ,
Mar 18, 2017 Mar 18, 2017

Is there a way to get the "Discount" to show as a percentage when a number is entered without needing to enter a decimal before the number?  For example, 15 is entered but 1500% displays instead of 15%

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 18, 2017 Mar 18, 2017

As I said, this would require using custom Format and Keystroke scripts... For the Format script you can use this:

if (event.value) event.value += "%";

And for the Keystroke you can use this:

event.rc = !isNaN(AFMergeChange(event));

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
New Here ,
Mar 20, 2017 Mar 20, 2017
LATEST

Thank you so much for all your assistance.  The form is complete.  You are awesome!  Have a wonderful and blessed week!

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