Copier le lien dans le Presse-papiers
Copié
I am trying to add two formulas to my pdf form:
The first formula is for BMI which is 703*weight in pounds/height inches squared. I made the BMI box a number initially but an error came up that said fields don't match. I Imagine it is either because it is a long decimal or because there is a zero in the denominator until someone types a value in there. I changed the field to reflect "none" in formatting and now it is showing "NaN" until something is typed. I would like for "NaN" not to show.
I have ZERO knowledge of javascript, and just need to know what to type in and where. I figure the solution to the first formula will help me solve the second formula issue.
Copier le lien dans le Presse-papiers
Copié
Copier le lien dans le Presse-papiers
Copié
Format field as number with 2 decimals.
Copier le lien dans le Presse-papiers
Copié
In your file you are missing parentheses at the end.
Copier le lien dans le Presse-papiers
Copié
Since those fields have calculations they won't be blank so there is no point to check if field is "" and since you can't divide with 0 you need to check that divisor in this case field "Text14" is not 0 for calculation to trigger, like this:
if(this.getField("Text14").value == 0)
event.value = "";
else
event.value = Number(this.getField("Text13").value)/Number(this.getField("Text14").value);
Copier le lien dans le Presse-papiers
Copié
Instead of Simplified field notation use this as custom calculation script:
var c1 = Number(this.getField("Calc1").value);
var c2 = Number(this.getField("Calc2").value);
var c3 = Number(this.getField("Calc3").value);
var x = c1+c2+c3;
if(x == 0)event.value = "";
else
event.value = 18000/(2*x);
Copier le lien dans le Presse-papiers
Copié
Post script you are using.
Copier le lien dans le Presse-papiers
Copié
This is the script: 703*pg8_2/(pg8_1*pg8_1). I've input this is the simplified field notation
Copier le lien dans le Presse-papiers
Copié
See if this works for you:
https://drive.google.com/uc?export=download&id=16Rm7Vy4-ua4a6e7RTgRk_lsbsCMGvRHH
Copier le lien dans le Presse-papiers
Copié
Yes! this works. Is there a way to limit the answer to two decimal points?
Copier le lien dans le Presse-papiers
Copié
Format field as number with 2 decimals.
Copier le lien dans le Presse-papiers
Copié
Copier le lien dans le Presse-papiers
Copié
In your file you are missing parentheses at the end.
Copier le lien dans le Presse-papiers
Copié
Copier le lien dans le Presse-papiers
Copié
Checking if the fields are empty is not enough. You also need to make sure the second field's value is not zero. See the code I posted below.
Copier le lien dans le Presse-papiers
Copié
Since those fields have calculations they won't be blank so there is no point to check if field is "" and since you can't divide with 0 you need to check that divisor in this case field "Text14" is not 0 for calculation to trigger, like this:
if(this.getField("Text14").value == 0)
event.value = "";
else
event.value = Number(this.getField("Text13").value)/Number(this.getField("Text14").value);
Copier le lien dans le Presse-papiers
Copié
Copier le lien dans le Presse-papiers
Copié
Instead of Simplified field notation use this as custom calculation script:
var c1 = Number(this.getField("Calc1").value);
var c2 = Number(this.getField("Calc2").value);
var c3 = Number(this.getField("Calc3").value);
var x = c1+c2+c3;
if(x == 0)event.value = "";
else
event.value = 18000/(2*x);
Copier le lien dans le Presse-papiers
Copié
NaN = Not a Number
This is a Format issue, can you share (part of) your document?
Copier le lien dans le Presse-papiers
Copié
Copier le lien dans le Presse-papiers
Copié
Use this code as the field's custom calculation script:
var v1 = Number(this.getField("pg8_1").valueAsString);
var v2 = Number(this.getField("pg8_2").valueAsString);
if (v1==0) event.value = "";
else event.value = (703*v2/(v1*v1));
Copier le lien dans le Presse-papiers
Copié
This typically happens when you divide a number by zero and try to apply the result to a Number field.
To avoid it you must use a script. If you post the exact formula you're using for that field's calculation we can help you convert it into such a script.
Copier le lien dans le Presse-papiers
Copié
This is the script: 703*pg8_2/(pg8_1*pg8_1)
I've input this is the simplified field notation
Copier le lien dans le Presse-papiers
Copié
As we assumed:
- input fields should have the "Number" format to avoid unwanted entries.
- the Simple Field Notation can't protect against division by zero or division by nothing, so you must use a JavaScript calculation.
Joker: calculated fields should be read only.
😉
Copier le lien dans le Presse-papiers
Copié
great. How do I add a tofixed(2) vaue to this script:
if(this.getField("pg8_4").valueAsString == "" || this.getField("pg8_5").valueAsString == "")
event.value = "";
else
event.value = Number(this.getField("pg8_4").value)/Number(this.getField("pg8_5").value);
Trouvez plus d’idées, d’événements et de ressources dans la nouvelle communauté Adobe
Explorer maintenant