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

Remove NAN:NAN time between cells

New Here ,
Jun 06, 2021 Jun 06, 2021

Copy link to clipboard

Copied

Hi

I have a custom Java code to caluclate times between Take Off  & landing. Format in HH:MM, format out should be HH:MM.  However, the result is displaying NaN:NaN which is annoying until you enter times. Here is my code: Seems to work, just the NaN is annoying whilst the cells are blank. 

 

var hrsStart = parseInt(this.getField("Take Off Z1").value.split(":")[0]);
var minStart = parseInt(this.getField("Take Off Z1").value.split(":")[1]);
var hrsEnd = parseInt(this.getField("Landing Z1").value.split(":")[0]);
var minEnd = parseInt(this.getField("Landing Z1").value.split(":")[1]);
if (minStart > minEnd) {
var minRez = 60 + minEnd - minStart;
var hrsRez = hrsEnd - 1 - hrsStart;
} else {
var minRez = minEnd - minStart;
var hrsRez = hrsEnd - hrsStart;
}
this.getField("Flight Time1").value = hrsRez + ":" + minRez;

TOPICS
Edit and convert PDFs , How to , JavaScript , PDF forms

Views

788

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 , Jun 07, 2021 Jun 07, 2021

Add condition to check if fields are empty:

if(this.getField("Take Off Z1").valueAsString == "" || this.getField("Landing Z1").valueAsString == "")
this.getField("Flight Time1").value = "";
else
this.getField("Flight Time1").value = hrsRez + ":" + minRez;

 

TIP: if you use code in "Flight Time1" field, instead of: this.getField("Flight Time1").value  you can use: event.value

Votes

Translate

Translate
Community Expert ,
Jun 06, 2021 Jun 06, 2021

Copy link to clipboard

Copied

Perform the calculation only when the cells are not empty.

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 ,
Jun 06, 2021 Jun 06, 2021

Copy link to clipboard

Copied

And how to initiate that? 

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 ,
Jun 07, 2021 Jun 07, 2021

Copy link to clipboard

Copied

Add condition to check if fields are empty:

if(this.getField("Take Off Z1").valueAsString == "" || this.getField("Landing Z1").valueAsString == "")
this.getField("Flight Time1").value = "";
else
this.getField("Flight Time1").value = hrsRez + ":" + minRez;

 

TIP: if you use code in "Flight Time1" field, instead of: this.getField("Flight Time1").value  you can use: 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
New Here ,
Jun 07, 2021 Jun 07, 2021

Copy link to clipboard

Copied

LATEST

Hi Nesa. 

 

Oohh thank you very much! worked perfect! Many thanks

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