Need negative number to show up as 0 on a calculated field

New Here ,
Dec 23, 2021 Dec 23, 2021

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!

TOPICS
How to

Views

104

Likes

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

correct answers 2 Correct answers

Adobe Community Professional , Dec 23, 2021 Dec 23, 2021

As validation script of FieldC use this:

if(event.value < 0)event.value = 0;

Likes

Translate

Translate
Adobe Community Professional , Jul 28, 2022 Jul 28, 2022

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 = "";}

 

Likes

Translate

Translate
Adobe Community Professional ,
Dec 23, 2021 Dec 23, 2021

Copy link to clipboard

Copied

As validation script of FieldC use this:

if(event.value < 0)event.value = 0;

Likes

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 ,
Dec 23, 2021 Dec 23, 2021

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.

Likes

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 ,
Dec 23, 2021 Dec 23, 2021

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!!!!

Likes

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 Beginner ,
Jul 28, 2022 Jul 28, 2022

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.

Likes

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
Adobe Community Professional ,
Jul 28, 2022 Jul 28, 2022

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 = "";}

 

Likes

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 Beginner ,
Jul 29, 2022 Jul 29, 2022

Copy link to clipboard

Copied

LATEST

WOW, WOW, WOW!!! You are a genius.Works perfectly.

Thank you so much!! 

Likes

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