Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


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

404

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

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

Likes

Translate

Translate
Adobe Community Professional ,
Jun 06, 2021 Jun 06, 2021

Copy link to clipboard

Copied

Perform the calculation only when the cells are not empty.

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

Copy link to clipboard

Copied

And how to initiate that? 

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

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

Copy link to clipboard

Copied

LATEST

Hi Nesa. 

 

Oohh thank you very much! worked perfect! Many thanks

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