Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

The value entered does not match the format of the field

Community Beginner ,
Jul 11, 2017 Jul 11, 2017

I have set up some basic formulas in my PDF.  Example....I have a Swing field and a Cycles field.  In the Cycles field under calculate I have a Simplified field notation:  (60*60)/Swing  The formula works fine but I have to have a number in Swing or it gives me a The value entered does not match the format of the field [Cycles]  - the format in Cycles is set up as a Number.  What do I need to change to be able to have a blank in Swing?

TOPICS
Acrobat SDK and JavaScript , Windows
7.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 11, 2017 Jul 11, 2017

JavaScript for Acrobat is not the same as JavaScript for the web - that makes it a bit harder to find a good resource. Take a look here for a book that is dedicated to Acrobat's JavaScript: Beginning JavaScript for Adobe Acrobat

Here are some general resources: Learning to Program JavaScript for Adobe Acrobat - KHKonsulting LLC

Then, once you are familiar with JavaScript, you need to work with the Acrobat JavaScript documentation in the Acrobat SDK.

The "Maximum" field should be fine, but take a

...
Translate
Community Expert ,
Jul 11, 2017 Jul 11, 2017

When there is no value in the "Swing" field, the value returned for an empty string is 0, which means you are dividing by zero - which results in "NaN" - or "Not a Number". This is - as the name suggests - not a number, and therefore does not fit into the number format that you associated with the field. There are two ways around this: You can either use a custom formatting script for your result field, or you can use a custom calculation script that will not perform the calculation when there is no valid number in the "Swing" field. I would go with the second route. Something like this should work:

var f = this.getField("Swing");

if (f.valueAsString != "") {

  event.value = (60*60)/f.value;

}

else {

  event.value = "";

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 11, 2017 Jul 11, 2017

The calculations are still working using that, but I still can't change Swing to a blank field.  I'm getting the value entered does not match the format of the field [Efficiency]

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 11, 2017 Jul 11, 2017

I think I'm finding my problem.  I am very inexperienced in JavaScript.  What I have done is convert an excel file to PDF and am trying to program 3 fields.  The first field will be filled in by the user with a number (however I want it blank to start).  I've labeled that Swing.  That will then calculate Cycles (60*60)/Swing.  The next field they will enter is labeled Bucket.  The field I call Maximum will calculate Cycles*Bucket.  Finally They will enter Volume in one field (named Volume) and Hours into another field (named Hours)  The final box is Efficiency, which calculates the total of Volume/Hours/Maximum.  I'm thinking I will need to write a custom calculation script for all 3 boxes or they will be off.  I plan to convert several things from excel to fillable pdf's and will need to learn how this works.  Is there a course you recommend?  Any help you can offer would be greatly appreciated for this form.  I have all the formula's working fine..but just can't clear all the boxes to start with a blank form.  

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 11, 2017 Jul 11, 2017

JavaScript for Acrobat is not the same as JavaScript for the web - that makes it a bit harder to find a good resource. Take a look here for a book that is dedicated to Acrobat's JavaScript: Beginning JavaScript for Adobe Acrobat

Here are some general resources: Learning to Program JavaScript for Adobe Acrobat - KHKonsulting LLC

Then, once you are familiar with JavaScript, you need to work with the Acrobat JavaScript documentation in the Acrobat SDK.

The "Maximum" field should be fine, but take a look at the script for Efficiency, and convert that to something similar to what I presented above.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 12, 2017 Jul 12, 2017

Karl.....thank you so much for your time!!!!  I'm plugging away again this morning.  I've tried this but am getting a SyntaxError.

The code I'm trying is:

var f = this.getField("Volume"Hours"Maximum");

if (f.valueAsString !="") {
  event.value =

(Volume/Hours/Maximum)/f.value;
}
else {
  event.value = "";
}

Is there any way I can attach the PDF so you could look at it, so it makes more sense?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 12, 2017 Jul 12, 2017

"Volume"Hours"Maximum" is not a field name.

What is this: (Volume/Hours/Maximum) ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 12, 2017 Jul 12, 2017

My PDF has 3 boxes that have calculations in them.

The final box I am trying to write code in is labeled efficiency.  That needs to calculate 2 fields that are entered by the user.  One field is called Volume, one is called Hours.  Efficiency is calculating the value of Volume divided by Hours divided by the field we got from the first code called Maximum.

I was trying to play with the previous code...but know I'm not doing it properly.  Any help is very much appreciated!  😃

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 12, 2017 Jul 12, 2017

You need to get the three values independent - you cannot combine the filed names as you did. Try something like this:

var volume = this.getField("Volume").value;

var hours = this.getField("Hours").value;

var maximum = this.getField("Maximum").value;

Then you can use the variables volume, hours and maximum in your calculation:

event.value = volume / hours / maximum;

Do yourself a favor and read up on the syntax of JavaScript, it will make your life much easier if you know what is valid and what will cause errors - and if something does report an error, you might be able to figure out why it's complaining about a certain construct. You cannot copy and paste your way to a successful solution. You need to be able to understand what the code snippets you find online are actually doing so that you can adjust them to your specific needs - or fix something half a year down the line when the requirements change.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 12, 2017 Jul 12, 2017

Thank you again for helping!  I will definitely read up on the syntax of JavaScript.  I am now able to clear the fields without error codes...however, my formula is not working properly.  My Cycles and Maximum are computing properly...but Efficiency is not doing any calculations.  I am missing something.

var volume = this.getField("Volume").value;
var hours = this.getField("Hours").value;
var hours = this.getField
("Maximum").value;

if (Volume.valueAsString !=""){event.value = Volume/Hours/Maximum}
if (Hours.valueAsString !="")
{event.value = Volume/Hours/Maximum}
if (Maximum.valueAsString !="") {event.value = Volume/Hours/Maximum}

event.value = volume/hours/maximum;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 12, 2017 Jul 12, 2017

Karl!

I did it!  I messed with a few things!  Thank you so much!  Here's what I did:

var Volume = this.getField("Volume").value;
var Hours = this.getField("Hours").value;
var Maximum = this.getField("Maximum").value;

if (Volume.valueAsString !=""){event.value = Volume/Hours/Maximum}
if (Hours.valueAsString !="")
{event.value = Volume/Hours/Maximum}
if (Maximum.valueAsString !="") {event.value = Volume/Hours/Maximum}

event.value = Volume/Hours/Maximum;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 12, 2017 Jul 12, 2017

Opps....I spoke too soon.  I'm going to step away from this for a tad and clear my head.  I'll keep you posted.  I am also reading your write up. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 12, 2017 Jul 12, 2017

This is the code to use:

var Volume = Number(this.getField("Volume").valueAsString);

var Hours = Number(this.getField("Hours").valueAsString);

var Maximum = Number(this.getField("Maximum").valueAsString);

if (Hours!=0 && Maximum!=0) event.value = (Volume/Hours)/Maximum;

else event.value = "";

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 12, 2017 Jul 12, 2017

Note I edited the code above slightly...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 12, 2017 Jul 12, 2017

Thank you both!  Karl, I still kept getting an error with yours (but the figures worked great!) however Try67's worked for me.  I can't thank you both enough!  You both are pro's at this.  I'm hoping to learn as much as I can.

I have one final PDF that I'm working on and have figured out pretty much the whole thing.  It is very similar to the first one that now works perfectly.

My second one has almost the same format....3 boxes that are programmable based off entries.  I know I have the first box called Maximum computed properly.  My second box however is where I KNOW I need to put in JavaScript but I believe I am messing up on the formula.  This field takes the value of Maximum and multiplies that by the amount the user enters into Bucket then it divides that by what the user enters into Depth multiplied by Width and divides that total by 27.   example:  (Maximum*Bucket) / ((Depth*Width)/27)

This is what I have done so far:

var Bucket = Number(this.getField("Bucket").valueAsString);

var Depth = Number(this.getField("Depth").valueAsString);

var Width = Width(this.getField("Width").valueAsString);

var Maximum = Maximum(this.getField("Maximum").valueAsString);

I'm thinking the next line would be:

if (Width!=0 && Maximum!=0) event.value = (Maximum*Bucket)/Depth*Width)/27;

else event.value = "";

BUT....I'm getting a SyntaxError. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 12, 2017 Jul 12, 2017

There is a problem in this line:

event.value = (Maximum * Bucket) / Depth * Width) / 27;

The number of opening "(" and closing ")" does not match - they have to always be in pairs. I assume you want this:

event.value = (Maximum * Bucket) / (Depth * Width) / 27;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 12, 2017 Jul 12, 2017

I'm no longer getting an error code...but it is not computing anything.

var Bucket = Number(this.getField("Bucket").valueAsString);

var Depth = Number(this.getField("Depth").valueAsString);

var Width = Width(this.getField("Width").valueAsString);

var Maximum = Maximum(this.getField("Maximum").valueAsString);

if (Width!=0&&Maximum!=0)event.value=(Maximum*Bucket)/(Depth * Width)/27;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 12, 2017 Jul 12, 2017

You can't just invent things and expect them to work... Why did you replace Number(...) with Width(...) and Maximum(...)? There are no such functions in JS.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 12, 2017 Jul 12, 2017

I hadn't even noticed I'd done that!  And that did make a huge difference.  Thanks again for all your tips and help!  I actually understand a lot more now!  I have a lot to learn!  Have a great afternoon!!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 12, 2017 Jul 12, 2017

In addition to that you have another issue in the code above. You should check whether Width and Depth are not zero, not Width and Maximum.

If Maximum is zero then you're dividing zero by a value, which is fine, but if Depth is zero you'll be dividing by zero, which is not allowed.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 13, 2017 Jul 13, 2017

Thank you!  I fixed the code with your advice.  How long have you been writing code?  How did you learn?  Again, Thank you for your help with this!  I'm interested in learning more.  We have several excel programs that would work better in Adobe. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 13, 2017 Jul 13, 2017

I've been writing code for Acrobat for more than a decade now, and code in general about twice that.

I taught myself JavaScript for Acrobat (and other Adobe applications), by trial and error, by following the good advice given by experts on these forums (and others, now mostly defunct), as well as by reading the API and parts of the PDF Specifications.

Some good resources to get you started:

http://www.adobe.com/devnet/acrobat.html

https://acrobatusers.com/tutorials/

http://www.pdfscripting.com/

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 21, 2017 Jul 21, 2017

Good Morning,

I have the PDF's calculating fine.  We sent them out to the guys on the field, they all have IPADS....and they can not get it to work.  I have tried downloading Adobe...and it will now let me fill in the fillable fields..but the calculations will not work.  What program can we use to have the calculations work on Ipads?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 21, 2017 Jul 21, 2017

Your best chance is with Readdle's PDF Expert, but even then it might not work, as support for scripts on mobile devices is very (very) limited.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 21, 2017 Jul 21, 2017

As try67 said, there are 3rd party PDF viewers that have more support for custom calculations than Adobe's mobile Reader. Designing a form and then trying to find a mobile PDF viewer is the wrong order: You need to first pick what PDF viewers you want to support (e.g. on desktop, iOS and Android platforms), and then design your form so that it only uses the subset of features that are supported by all viewers.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines