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
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;
Copy link to clipboard
Copied
Try this:
if (event.value && event.target.value!="") event.value = Number(event.target.value)+Number(event.value);
Copy link to clipboard
Copied
So you want to use three fields for this, or just two?
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?
Copy link to clipboard
Copied
You can use the simplified notation:
Copy link to clipboard
Copied
right so i want to do that without the 3rd box
Copy link to clipboard
Copied
Thank you! I was thinking in a more complicated way and it wasn't working for me. You are awesome!
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.
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.
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;
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.
Copy link to clipboard
Copied
how would we alter this to be its own box instead of taking another field?
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.
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.
Copy link to clipboard
Copied
Try this:
if (event.value && event.target.value!="") event.value = Number(event.target.value)+Number(event.value);
Copy link to clipboard
Copied
Perfect! thank you so much. you all are awesome at this.