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

Field shows zero instead of nothing

New Here ,
Oct 09, 2025 Oct 09, 2025

Earlier this year i created a form with some simple calculations and some fields with java script. User have the choice to fill it in by hand (print and pencil) or use the form online or offline. 

Last week i noticed that the form shows the calculation fields and the Java Script based fields show a zero. And this zero is also printed when a user wanted to fill it in manualy. 

 

var getal1 = this.getField("veld1").value;
var getal2 = this.getField("veld2").value;

if (!isNaN(getal1) && !isNaN(getal2)) {
event.value = Number(getal1) - Number(getal2);
} else {
event.value = "";
}

 

Scherm­afbeelding 2025-10-09 om 14.01.16.png

Who has a solution,

Best,

Ton

TOPICS
JavaScript , PDF forms
143
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
1 ACCEPTED SOLUTION
Community Expert ,
Oct 09, 2025 Oct 09, 2025

Add this script as a Validation script in the Total field:

if (event.value == 0) {event.value = "";}

Acrobate du PDF, InDesigner et Photoshopographe

View solution in original post

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 ,
Oct 09, 2025 Oct 09, 2025

That's because isNaN returns false when provided an empty string (which is equivalent to zero in JS). So you need to add a separate check for that in your if-condition.

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 ,
Oct 09, 2025 Oct 09, 2025

Add this script as a Validation script in the Total field:

if (event.value == 0) {event.value = "";}

Acrobate du PDF, InDesigner et Photoshopographe
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 ,
Oct 09, 2025 Oct 09, 2025

That would also hide the result if it's legitimately zero. For example if the amounts are -10 and 10. You might not want that to happen...

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
New Here ,
Oct 09, 2025 Oct 09, 2025
LATEST

Thanks for the replies, problem solved.

 

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