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

NaN being displayed

Community Beginner ,
Sep 03, 2025 Sep 03, 2025

I am trying to get rid of NaN being dsiplayed. 

event.value = this.getField("End Time Day One").value - this.getField("Start Time Day One").value;
if (isNaN(event.value) || event.value == 0) {
event.value = "";
}

var total = this.getField("Total Hours Day One").value;
if (this.getField("Check Box 1").value != "Off") {
event.value = Number("Total Hours Day One") - 1;
} else {
event.value = Number("Total Hours Day One");
}

TOPICS
JavaScript
190
Translate
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 ,
Sep 03, 2025 Sep 03, 2025

To access a field's value you must use getField("...").value, not just specify the field's name... You did it correctly in the first line of code, but not later on. Also, the second part of your code overrides the first one. You should put all the second part inside an "else" clause.

Translate
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 ,
Sep 03, 2025 Sep 03, 2025

So I am extremely new at this. I am not sure where I stopped using getField. Can you eloborate?

Thank you

Translate
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 ,
Sep 03, 2025 Sep 03, 2025

Number("Total Hours Day One")

Translate
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 ,
Sep 03, 2025 Sep 03, 2025

I do not understand. Sorry

Translate
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 ,
Sep 03, 2025 Sep 03, 2025

Number("Total Hours Day One") should be Number(this.getField("Total Hours Day One").value) or, since you defined the value as total: Number(total)

Translate
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 ,
Sep 03, 2025 Sep 03, 2025

Thank you

Translate
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 ,
Sep 03, 2025 Sep 03, 2025

Hi @brantpro1 ,

 

There were a few things with the original work that still wasn't working right.

 

I've attached the form (linked below) with some improvements. 

 

Translate
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 ,
Sep 04, 2025 Sep 04, 2025

Hello,

Thank you for the improvements. Where are the calculations and javascript. When I prepare a form and look at the properties, I see no calculations or javascript to excute the function.

Translate
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 ,
Sep 04, 2025 Sep 04, 2025

My apologies @brantpro1 ,

 

I moved the custom calculation script to the Total Hours Worked Field.

Translate
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 ,
Sep 05, 2025 Sep 05, 2025

Thank you

Translate
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 ,
Sep 05, 2025 Sep 05, 2025
LATEST

@brantpro1 ,

 

Sorry again... I meant to say that the Total Hours Day One, Total Hours Day Two, and the Total Hours Day Three fields have their own custom calculation script.

 

Here's the link to the updated PDF file:  

 

 

 

See example scripts below:

 

Custom calculation script for Total Hours Day One

var name = this.getField("Name").value;
var day1 = this.getField("Day One").value
var startDay1 = this.getField("Start Time Day One").value;
var endDay1 = this.getField("End Time Day One").value;
var workHours1 = Number(endDay1) - Number(startDay1);
var checkBX1 = getField("Check Box 1");

if (name !=="" && day1 !=="" && (startDay1 !== "- Start Time -" && endDay1 !== "- End Time -")) {

  (checkBX1.value != "Off" ) ? event.value = workHours1 -1 : event.value = workHours1;
  
  } else {

 event.value =""

}

 

Custom calculation script for Total Hours Day Two

 

 

var name = this.getField("Name").value;
var day2 = this.getField("Day Two").value
var startDay2 = this.getField("Start Time Day Two").value;
var endDay2 = this.getField("End Time Day Two").value;
var workHours2 = Number(endDay2) - Number(startDay2);
var checkBX2 = getField("Check Box 2");

if (name !=="" && day2 !=="" && (startDay2 !== "- Start Time -" && endDay2 !== "- End Time -")) {

  (checkBX2.value != "Off" ) ? event.value = workHours2 -1 : event.value = workHours2;
  
  } else {

 event.value =""

}

 

Custom calculation script for Total Hours Day Three

var name = this.getField("Name").value;
var day3 = this.getField("Day Three").value
var startDay3 = this.getField("Start Time Day Three").value;
var endDay3 = this.getField("End Time Day Three").value;
var workHours3 = Number(endDay3) - Number(startDay3);
var checkBX3 = getField("Check Box 3");

if (name !=="" && day3 !=="" && (startDay3 !== "- Start Time -" && endDay3 !== "- End Time -")) {

  (checkBX3.value != "Off" ) ? event.value = workHours3 -1 : event.value = workHours3;
  
  } else {

 event.value =""

}

 

Translate
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 ,
Sep 04, 2025 Sep 04, 2025

Not a good idea to upload a form with a list of people and corresponding PINs.

Translate
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 ,
Sep 04, 2025 Sep 04, 2025

Appreciate the advice. I figured this wasa a safe community.

Translate
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