Skip to main content
Inspiring
June 14, 2023
Answered

javascript different in acrobat and acrobat online

  • June 14, 2023
  • 3 replies
  • 2482 views

I have this javascript in a pdf form: var f1 = this.getField("Text88"); var f2 = this.getField("Text89"); if (f1.value == "" || f2.value == "") { event.value = "NaN"; } if (f1.value === 0 && f2.value === 0) { event.value = "0"; } if (event.value) event.value = parseFloat(event.value).toPrecision(3) and it works in adobe acrobat but not adobe acrobat online. In adobe acrobat the calculated field is blank. In adobe acrobat online there is a 0 in the calculated field. Is there a way to fix it so that the calculated field is bland in adobe acrobat online.

This topic has been closed for replies.
Correct answer William2600964700to

Use this code as the field's custom Calculation script:

 

var f1 = this.getField("Text80").valueAsString;
var f2 = this.getField("Text81").valueAsString;
if (f1 == "" || f2 == "") {
    event.value = "";
} else {
	f1 = Number(f1);
	f2 = Number(f2);
	event.value = ((f2/2)+f1).toFixed(3);
}

 

Set the Format setting to None.

 

 


OMG!!  You are a genius.  It works.  Thank you so much.

3 replies

Bernd Alheit
Community Expert
Community Expert
June 14, 2023

What values does you at the fields?

Inspiring
June 14, 2023

If I open in Adobe Acrobat the field shows NaN but if I open it with Adobe Online in Chrome it shows 0

Bernd Alheit
Community Expert
Community Expert
June 14, 2023

Adobe Online is not the same as Adobe Acrobat.

Inspiring
June 14, 2023

Actually, I should have said the output is NaN in Adobe Acrobat and a 0 in Adobe online

Inspiring
June 14, 2023

And I want the ouput to be either NaN or blank (not bland) when opened with Adobe online

 

Bernd Alheit
Community Expert
Community Expert
June 14, 2023

Where does you set the field to blank?