Skip to main content
Participant
February 20, 2018
Answered

The value entered does not match the format of the field; java script

  • February 20, 2018
  • 2 replies
  • 1376 views

I created a custom script that equates a percentage and that works fine. However, I get the error message of "the value entered does not match the format of the field". I believe that by other discussions I have read that I need to set a script that ensures the field has a non-zero value but don't know how to write it. My current calculation is: event.value = this.getField("Sponsor Total").value/this.getField("Overall Project Total").value

This topic has been closed for replies.
Correct answer George_Johnson

var numerator = +getField("Sponsor Total").value;

var denominator = +getField("Overall Project Total").value;

event.value = denominator !== 0 ? numerator / denominator : "";

That last line translated to English would be: If the denominator is not equal to zero, set this field's value to the numerator divided by the denominator. Otherwise, make it blank.

2 replies

Thom Parker
Community Expert
Community Expert
October 20, 2020
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
George_JohnsonCorrect answer
Inspiring
February 20, 2018

var numerator = +getField("Sponsor Total").value;

var denominator = +getField("Overall Project Total").value;

event.value = denominator !== 0 ? numerator / denominator : "";

That last line translated to English would be: If the denominator is not equal to zero, set this field's value to the numerator divided by the denominator. Otherwise, make it blank.

Participant
February 20, 2018

Thank you, George...worked like a charm!