Copy link to clipboard
Copied
Hi all!
I'm trying to create a script in Adobe Forms where variable in an adjacent field will return different values in the target field. I would like the returning value to stay empty if the adjacent field is empty [if (v = empty) event.value = ""]. I've attempted to read through other answers, but haven't been successful in applying to this scenario.
var v = Number(this.getField("ATPRow1").value);
if (v >= 0.01 && v <= 14.99) event.value = 2.75;
if (v >= 15 && v <= 74.99) event.value = 3.85;
if (v >= 75) event.value = 5.06;
if (v == 0) event.value = 0.88;
Can anyone help? Thanks in advance!
Copy link to clipboard
Copied
A null string, "", under some situations is treated like zero in JavaScript. The only way to access the null value is to use the "valueAsString" property or the "String" constrictor.
var v = this.getField("ATPRow1").valueAsString;
if(v == "") event.value = "";
else {
v = Number(v);
if (v >= 0.01 && v <= 14.99) event.value = 2.75;
if (v >= 15 && v <= 74.99) event.value = 3.85;
if (v >= 75) event.value = 5.06;
if (v == 0) event.value = 0.88;
}
Copy link to clipboard
Copied
In the code above the variable "v" will never be an empty string because you're explicitly using the Number constructor, and Number("") will return zero. You need to first check if the value of the field (use valueAsString instead of value, by the way) is an empty string, and if it's not proceed to convert it to a number and perform the rest of your logic.
Copy link to clipboard
Copied
A null string, "", under some situations is treated like zero in JavaScript. The only way to access the null value is to use the "valueAsString" property or the "String" constrictor.
var v = this.getField("ATPRow1").valueAsString;
if(v == "") event.value = "";
else {
v = Number(v);
if (v >= 0.01 && v <= 14.99) event.value = 2.75;
if (v >= 15 && v <= 74.99) event.value = 3.85;
if (v >= 75) event.value = 5.06;
if (v == 0) event.value = 0.88;
}
Copy link to clipboard
Copied

