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

If blank then do not calculate?

New Here ,
Mar 09, 2016 Mar 09, 2016

I'm attempting to create a custom calculation script for a discount field (in $) where it takes the value of a master discount field (in %) times the quantity of the item by the price. The issue is that I have the master discount field set to be blank should no value be entered and this seems to interrupt the calculation. I'm quite inexperienced with javascript so I'd appreciate it if you could take a look at my issue and let me know what I might need to do in order to fix it.

This is the simple formula that I need to get the required total:

(QTY1*UnitPrice1)*(Discount1/100)

I am attempting to say that if the value = blank/null then do not perform the calculation otherwise perform (A*B)*(C/100):

if (this.getField("Discount1").valueAsString=="") then ???

else event.value = ( this.getField("QT1").value * this.getField("UnitPrice1").value ) * ( this.getField("Discount1").value / 100 );

Thank you!

TOPICS
Acrobat SDK and JavaScript
591
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 Expert , Mar 09, 2016 Mar 09, 2016

if (this.getField("Discount1").valueAsString=="") event.value = "";

else event.value = ( this.getField("QT1").value * this.getField("UnitPrice1").value ) * ( this.getField("Discount1").value / 100 ); 

Translate
Community Expert ,
Mar 09, 2016 Mar 09, 2016

if (this.getField("Discount1").valueAsString=="") event.value = "";

else event.value = ( this.getField("QT1").value * this.getField("UnitPrice1").value ) * ( this.getField("Discount1").value / 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 09, 2016 Mar 09, 2016
LATEST

Excellent, that worked perfectly! Thank you try67!

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