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

how to add or subtract from given calc field

Explorer ,
Feb 21, 2022 Feb 21, 2022

Copy link to clipboard

Copied

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

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
2 ACCEPTED SOLUTIONS
Community Expert ,
Feb 22, 2022 Feb 22, 2022

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

Try this:

 

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

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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?

 

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

Copy link to clipboard

Copied

You can use the simplified notation:

 

Capture_182.png

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

LATEST

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

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

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;

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

how would we alter this to be its own box instead of taking another field?

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

i tried switching this to just add a number entered and it instead adds the number to the end of the previous 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 Expert ,
Feb 22, 2022 Feb 22, 2022

Copy link to clipboard

Copied

Try this:

 

if (event.value && event.target.value!="") event.value = Number(event.target.value)+Number(event.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
Explorer ,
Feb 22, 2022 Feb 22, 2022

Copy link to clipboard

Copied

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

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