Copy link to clipboard
Copied
Hello. I'm really new to this and am creating a form where I need to subtract Field B from Field A and make the total appear in Field C. This part I understand. The problem I'm running into is if the total equals a negative number, I want it to show up as zero. Is that possible? I've had a few other codes I've tried to just get it to display, but as soon as I do another formula within the pages, it makes the total disappear. If someone could please help with a good calculation code, I would really appreciate it!
Copy link to clipboard
Copied
As validation script of FieldC use this:
if(event.value < 0)event.value = 0;
Copy link to clipboard
Copied
You can use this as 'Validation' script of "FieldA":
var num = Number(event.value);
if(num > 0){
this.getField("FieldB").value = 0;
this.getField("FieldC").value = "";}
else if(num < 0){
this.getField("FieldB").value = Math.abs(num);
this.getField("FieldC").value = Math.abs(num)/65;}
else{
this.getField("FieldB").value = "";
this.getField("FieldC").value = "";}
Copy link to clipboard
Copied
As validation script of FieldC use this:
if(event.value < 0)event.value = 0;
Copy link to clipboard
Copied
I've used that one, but how do I also make it calculate in the same field? I want Field C to do the math and also not to display anything negative.
Copy link to clipboard
Copied
Nevermind! You're a genius!! It worked! I had been trying to put that code in the custom script for calculations!! Thank you so much!!!!
Copy link to clipboard
Copied
Along those lines, I am running into a challenge with an enrollment form I need help with.
I have a form field (FieldB) that needs to equal the value calculated in another field (FieldA) but ONLY if it’s a negative number, and then I want to convert it to a positive number.
However, if the value of the other field (FieldA) is positive, I want field (FieldB) to display 0.
Finally, if FieldB is populated with a positive number, then I need FieldC to input with the FieldB divided by 65. Otherwise, FieldC will remain blank.
Copy link to clipboard
Copied
You can use this as 'Validation' script of "FieldA":
var num = Number(event.value);
if(num > 0){
this.getField("FieldB").value = 0;
this.getField("FieldC").value = "";}
else if(num < 0){
this.getField("FieldB").value = Math.abs(num);
this.getField("FieldC").value = Math.abs(num)/65;}
else{
this.getField("FieldB").value = "";
this.getField("FieldC").value = "";}
Copy link to clipboard
Copied
WOW, WOW, WOW!!! You are a genius.Works perfectly.
Thank you so much!!
Copy link to clipboard
Copied
Hi Nesa,
Thank you for that! That worked for one part of my form. My other issue is, i need to add two cells/fields but i need the result to only show "0" if the result is 0 or positive and the negative amount if the result is negative.
Appreciate any help you can provide!!! Thank you!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now