Copy link to clipboard
Copied
I have a form and calculator I created. The calculations all work perfectly and sum correctly.
The problem is I get 2 error messages same message 2 different field entries.
Basic message: "Value does not match format".
These 2 messages pop-up with every field entry made until the entire calculator is filled. This even happens with the text only entries.
So as the calculator works, can I just hide the error messages?
If anyone wants to look at the calculator I can sen it to you.
Thank you for any help.
Copy link to clipboard
Copied
In that case you have to change this line:
if (v1 != 0) {
To:
if (v2 != 0) {
Copy link to clipboard
Copied
This error message typically appears when you try to apply a non-numeric value to a field set up as having a Number format.
Most likely, it's caused by an attempt to divide by zero, which yields a non-numeric result, since it's an illegal operation.
Copy link to clipboard
Copied
Hi try67,
I thought that might be the issue. My calculator when the entries are cleared all say "0". So any numbers I put in until the form is filled is trying to divide from the number already in the field. How do I clear the field to say nothing?
Thx!
Sheryl
Copy link to clipboard
Copied
Hiding error messages can add more problems to your form. There tell you of an issue that probably needs to be addressed before your form of script will work properly.
You can set the problem field's format to "None" and observe the result of the division.
JavaScript supports some numeric values that do not comply to the "Number" format. They are "Infinity", "-Infinity" and scientific notation. Since these numbers are not in the format of numeric digits, sign and decimal point they do not match the "Number" format. You will need to add code to avoid division by zero or allow the non "Number" format values.
Setting the field to a null string will not eliminate the error since a null string will be treated as a zero in JavaScript. You need to use an "if" statement to see if the divisor is not zero before performing any division. This requires custom JavaScript coding.
Copy link to clipboard
Copied
Hi gkaiseril,
I tried javascript which worked in the sense the error messages were gone, but the calculations were wrong.
Example currently using in:
Excel: BC14=BC13/BC12
Acrobat: BC13/BC12 Go to: BC14
So I changed to JavaScript.
This is the JavaScript used, but it is not giving me the correct answer when calculated. (No error messages).
function () { // Get the field values, as numbers
var v1 = +getField("BC13").value;
var v2 = +getField("BC12").value;
if (v1 !== 0)
{ event.value = 100 * (v1 - v2) / v1; }
else { event.value = "";
}
})();I reached out to others and this was the suggestion made:
change +getfield to .getfield
I did make the change and got syntex error messages.
Copy link to clipboard
Copied
Why all of this?
event.value = 100 * (v1 - v2) / v1;
Just use:
event.value = v2 / v1;
The rest of the code is fine.
Copy link to clipboard
Copied
Yes this makes sense:
function () { // Get the field values, as numbers
var v1 = +getField("BC13").value;
var v2 = +getField("BC12").value;
if (v1 !== 0)
{ event.value = v2 / v1; }
else { event.value = "";
}
})();
I now get:
SyntaxError: function statement requires a name
1: at line 2
for this line
var v1 = +getField("BC13").value;
Copy link to clipboard
Copied
You don't need the function definition. Use this code:
var v1 = Number(this.getField("BC13").value);
var v2 = Number(this.getField("BC12").value);
if (v1 != 0) {
event.value = v2 / v1;
} else {
event.value = "";
}
Copy link to clipboard
Copied
Thank you try67,
I had to flip the values to calculate properly
Suggested: event.value = v2 / v1;
Flipped: event.value = v1 / v2;
Copy link to clipboard
Copied
In that case you have to change this line:
if (v1 != 0) {
To:
if (v2 != 0) {
Copy link to clipboard
Copied
Hi try67,
It works both ways and calculates properly.
Thank you so very much for your help.
Best,
Sheryl
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more