Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Add this script as a Validation script in the Total field:
if (event.value == 0) {event.value = "";}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Add this script as a Validation script in the Total field:
if (event.value == 0) {event.value = "";}
Copy link to clipboard
Copied
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...
Copy link to clipboard
Copied
Thanks for the replies, problem solved.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now