Skip to main content
Participant
April 8, 2025
解決済み

JavaScript error - wrong format

  • April 8, 2025
  • 返信数 9.
  • 1031 ビュー

I have created a fillable PDF for our music department to use.

Box A = number of students you teach

Box B = number of students who participated in a specific event.

 

Box C = percent of students who particpated

  • This box is read only and I have the calculation set to Box B/Box A. I have it formatted to be a percentage.

 

Whenever I go to preview the document it pops up with the error that Box C is the wrong format (Even when I haven't typed anything into it). How do I fix this?

 

解決に役立った回答 Thom Parker

Please see this article:

https://acrobatusers.com/tutorials/how-to-do-not-so-simple-form-calculations/

 

Is your original calculation on "Box C" using Simplified field notation? If it is then your field names are the problem. Spaces and special characters in the field name are a problem for this type of calculation. Follow the instructions from Try67 for using a custom calculation script. 

 

返信数 9

Thom Parker
Community Expert
Thom ParkerCommunity Expert解決!
Community Expert
April 8, 2025

Please see this article:

https://acrobatusers.com/tutorials/how-to-do-not-so-simple-form-calculations/

 

Is your original calculation on "Box C" using Simplified field notation? If it is then your field names are the problem. Spaces and special characters in the field name are a problem for this type of calculation. Follow the instructions from Try67 for using a custom calculation script. 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
victoria_8032作成者
Participant
April 8, 2025

Yes I think I was using simplified. Thank you for the article! Like I said, I'm very new to this so I appreciate all of the help.

Thom Parker
Community Expert
Community Expert
April 8, 2025

Change the field names so they do not contain any spaces. Then simplified field notation should work. 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Bernd Alheit
Community Expert
Community Expert
April 8, 2025

Enter a value (not zero) in Box A.

victoria_8032作成者
Participant
April 8, 2025

The issue I'm going to run into is that some people will not need to fill out these boxes. They are specific to piano students and not everyone teaches piano. So if they leave it blank, it will continue to give them this error message.

try67
Community Expert
Community Expert
April 8, 2025

You need to use a script that takes that into account, and if Box A is blank (or zero) it doesn't perform the calculation. Something like this:

 

var v1 = Number(this.getField("Box B").valueAsString);
var v2 = Number(this.getField("Box A").valueAsString);
if (v2==0) event.value = "";
else event.value = v1/v2;