• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
0

If Greater than Multiple by

New Here ,
Sep 12, 2024 Sep 12, 2024

Copy link to clipboard

Copied

I am trying to create a pdf javaScript formula that calculates  if a field is greater than 2 multiple that field's value by 25 but not to exceed $250

TOPICS
Create PDFs , JavaScript , PDF , PDF forms

Views

480

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
1 ACCEPTED SOLUTION
Community Expert ,
Sep 12, 2024 Sep 12, 2024

Copy link to clipboard

Copied

Use the following custom calculation script:

var fld=this.getField("theField").value;

if(fld>2)

{event.value=fld*25}

else

{event.value=""}

if(event.value>250)

{event.value=250}

View solution in original post

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 ,
Sep 12, 2024 Sep 12, 2024

Copy link to clipboard

Copied

Use the following custom calculation script:

var fld=this.getField("theField").value;

if(fld>2)

{event.value=fld*25}

else

{event.value=""}

if(event.value>250)

{event.value=250}

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 ,
Sep 12, 2024 Sep 12, 2024

Copy link to clipboard

Copied

Consider adding an 'else' condition to reset the field to blank or 0 if the value initially exceeds 2 but subsequently drops below 2.

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 ,
Sep 12, 2024 Sep 12, 2024

Copy link to clipboard

Copied

Good point.  Answer edited.

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 ,
Sep 12, 2024 Sep 12, 2024

Copy link to clipboard

Copied

The order you added them is not correct, though.

It should be if - else if - else.

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 ,
Sep 12, 2024 Sep 12, 2024

Copy link to clipboard

Copied

Yes you can do it that way and I usually would, but I made an adjustment to what I already had.  My script works.  The first if/else statement calculates the value.  The next if statement takes that value and adjusts it down to 250 if it is > 250.

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
New Here ,
Sep 12, 2024 Sep 12, 2024

Copy link to clipboard

Copied

Thanks, that works perfectly.

 

Now,  I trying to do something similar.

 

If the value of that field is greater than 2 there's a 5% tax added but if it's greater than 3 there's a 10% tax added.

 

 

 

 

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 ,
Sep 12, 2024 Sep 12, 2024

Copy link to clipboard

Copied

Try this:

var fld = this.getField("theField").value;
var result = 0;
var maxLimit = 250;

if (!isNaN(fld) && fld > 2) {
 result = fld * 25;

 if (fld > 2 && fld <= 3) {
  result = result * 1.05;}
 else if (fld > 3) {
  result = result * 1.10;}}

event.value = Math.min(result, maxLimit);

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
New Here ,
Sep 13, 2024 Sep 13, 2024

Copy link to clipboard

Copied

I guess I misspoken. The formula needs to indicate if the field is greater than 2, the value should be 5% and  if the field is greater than 3 the value should be 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 ,
Sep 13, 2024 Sep 13, 2024

Copy link to clipboard

Copied

% of what?  The result?  Use Nesa's script but change 1.05 to .05 and change 1.10 to .1

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
New Here ,
Sep 13, 2024 Sep 13, 2024

Copy link to clipboard

Copied

LATEST

Just ment to determine if the tax value is 5% or 10%. I'm using another field to calculate the value based on that field..

 

in other words I used the 1st java script to determine "this field " is greater han 2 multiple by 25. 
I need new field that calculates if "the field"  is greater than 2  the value = .5 and if "the field " is greater than 3 the values = .10.


I'm sorry I made it confusing 

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