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

Trying to hide a NaN result with conditional formatting

Explorer ,
Feb 26, 2021 Feb 26, 2021

Copy link to clipboard

Copied

I'm working on a form that compares two sets of numbers, the first of which can result in a NaN result until data is plugged in. I have tried a handful of things, but wherever I plug in the NaN suppressing code, I end up hiding the actual results when there are numbers, so I'm turning to you lovely people!

I currently have the following code in a custom calculation script:

var CHANGEA=this.getField("CurrentMeetA").value - this.getField("CombineMeetA").value;

if (CHANGEA>=0) event.value = Math.round(CHANGEA) + "\n fewer";

else event.value = Math.round(Math.abs(CHANGEA)) + "\n more"
event.target.textColor = CHANGEA >= 0 ? ["RGB", 0.3137 , 0.702, 0.2471 ] : ["RGB", 0.9373 , 0.2784, 0.1765 ];

 I'm fine if it shows a "0 fewer" result (as it does for the quarterly, monthly, and weekly columns based on the annual column when the form is blank), but don't want a NaN result before people fill in the form.

Below is the form itself in case my description is confusing.

kateb89895260_0-1614353038301.png

Thank you for your assistance! I am pretty stoked to have gotten as far as I did without running into a wall, but this part is my last hurdle and I've tried several approaches with no luck!

TOPICS
JavaScript , PDF forms

Views

540

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 1 Correct answer

Community Expert , Feb 26, 2021 Feb 26, 2021

Hi,

 

You should be able to change you code to this :

var CHANGEA=this.getField("CurrentMeetA").value - this.getField("CombineMeetA").value;
if (isNaN(CHANGEA)){
CHANGEA=0;
}

if (CHANGEA>=0) event.value = Math.round(CHANGEA) + "\n fewer";

else event.value = Math.round(Math.abs(CHANGEA)) + "\n more"

 

Malcolm

Votes

Translate

Translate
Community Expert ,
Feb 26, 2021 Feb 26, 2021

Copy link to clipboard

Copied

Hi,

 

You should be able to change you code to this :

var CHANGEA=this.getField("CurrentMeetA").value - this.getField("CombineMeetA").value;
if (isNaN(CHANGEA)){
CHANGEA=0;
}

if (CHANGEA>=0) event.value = Math.round(CHANGEA) + "\n fewer";

else event.value = Math.round(Math.abs(CHANGEA)) + "\n more"

 

Malcolm

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 26, 2021 Feb 26, 2021

Copy link to clipboard

Copied

Ahhh, perfect! Thank you so much!

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
Enthusiast ,
Feb 26, 2021 Feb 26, 2021

Copy link to clipboard

Copied

Did you format your fields to 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
Explorer ,
Feb 26, 2021 Feb 26, 2021

Copy link to clipboard

Copied

LATEST

No, I did not, because I needed the field to return text after the number, so I assumed formatting to a number would cause a conflict.

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