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

how to add or subtract from given calc field

Explorer ,
Feb 21, 2022 Feb 21, 2022

im trying to add or subtract numbers in a field by entering the numbers into the actual calculated field. exp, field box calc is "var1+var2=x" so lets say x= 90. i want to subtract 22 from the box with 90 by entering 22 into the box and it will display 68

TOPICS
Create PDFs , General troubleshooting , How to , JavaScript
1.8K
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
2 ACCEPTED SOLUTIONS
Community Expert ,
Feb 22, 2022 Feb 22, 2022

This is a very confusing way of doing things, but if you really want to do it, you can use this code as the custom Validation script of the second field:

 

if (event.target.value=="") event.value = Number(this.getField("field1").valueAsString)-event.value;
else event.value = Number(event.target.value)-event.value;

View solution in original post

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 ,
Feb 22, 2022 Feb 22, 2022

Try this:

 

if (event.value && event.target.value!="") event.value = Number(event.target.value)+Number(event.value);

View solution in original post

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 ,
Feb 21, 2022 Feb 21, 2022

So you want to use three fields for this, or just two?

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
Explorer ,
Feb 21, 2022 Feb 21, 2022

2. so i have a total of 102 which is a set number. i want another field to display that number and to minus however much is input into the box that displays that number by entering the number into the same box. so it will display 102 when opened and say i want to minus 22 from that box. i want to just enter 22 into the box that says 102 and it to calculate it to 80. is that possible?

 

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 ,
Feb 21, 2022 Feb 21, 2022

You can use the simplified notation:

 

Capture_182.pngexpand image


Acrobate du PDF, InDesigner et Photoshoptographe
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
Explorer ,
Feb 21, 2022 Feb 21, 2022

right so i want to do that without the 3rd box

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 ,
Jul 20, 2023 Jul 20, 2023
LATEST

Thank you! I was thinking in a more complicated way and it wasn't working for me. You are awesome!

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 ,
Feb 22, 2022 Feb 22, 2022

Rather than saying what you don't want, you should say what you do want and how.
Please, elaborate your explanations.


Acrobate du PDF, InDesigner et Photoshoptographe
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
Explorer ,
Feb 22, 2022 Feb 22, 2022

This was close to what i want to do.

var a = this.getField("field1").value;
var f = event.value;

event.value = a;

if (a !=="" && f !=="") {event.value = a - f;}

if (a =="" && f !=="") {event.value ="";}

but instead of just subtracting the first number thats entered from the total of 120 i want it to continue subtracting from the previous calculation. so when you enter 11 into the field it will display 109. then enter 11 into the field again with 109 and it calculate 98.

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 ,
Feb 22, 2022 Feb 22, 2022

This is a very confusing way of doing things, but if you really want to do it, you can use this code as the custom Validation script of the second field:

 

if (event.target.value=="") event.value = Number(this.getField("field1").valueAsString)-event.value;
else event.value = Number(event.target.value)-event.value;
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
Explorer ,
Feb 22, 2022 Feb 22, 2022

Perfect! That will work well enough. i wish there was an easier way to reset the number back to the 1st field but this will do just fine. im actually doing a pdf for pathfinder if u know what that is so this is for hit point loss and i will implement this in for exp gain as well.

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
Explorer ,
Feb 22, 2022 Feb 22, 2022

how would we alter this to be its own box instead of taking another 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 Expert ,
Feb 22, 2022 Feb 22, 2022

Try this:

 

if (event.value && event.target.value!="") event.value = Number(event.target.value)-event.value;

 

It will also allow you to clear the field entirely.

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
Explorer ,
Feb 22, 2022 Feb 22, 2022

i tried switching this to just add a number entered and it instead adds the number to the end of the previous number.

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 ,
Feb 22, 2022 Feb 22, 2022

Try this:

 

if (event.value && event.target.value!="") event.value = Number(event.target.value)+Number(event.value);

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
Explorer ,
Feb 22, 2022 Feb 22, 2022

Perfect! thank you so much. you all are awesome at this.

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