Skip to main content
Ton Persoon
Participant
October 9, 2025
Answered

Field shows zero instead of nothing

  • October 9, 2025
  • 3 replies
  • 177 views

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 = "";
}

 

Who has a solution,

Best,

Ton

Correct answer JR Boulay

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

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

3 replies

Ton Persoon
Participant
October 9, 2025

Thanks for the replies, problem solved.

 

JR Boulay
Community Expert
JR BoulayCommunity ExpertCorrect answer
Community Expert
October 9, 2025

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

if (event.value == 0) {event.value = "";}
Acrobate du PDF, InDesigner et Photoshopographe
try67
Community Expert
Community Expert
October 9, 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...

try67
Community Expert
Community Expert
October 9, 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.