Skip to main content
KristiD5
Participating Frequently
May 16, 2019
Question

Percent field defaults to 0 rather than blank

  • May 16, 2019
  • 1 reply
  • 1906 views

I have a field formatted as a % field that I would like to show as blank until someone enters in a value.  However, it automatically defaults to show "0.0%".  I've found answers that say to use the validation of

if (event.value==0) event.value = "";

but when I copy/paste that it doesn't work.  I also have the validation of

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

event.value = event.value / 100 ;

}

so that people can just type in a number rather than having to deal with decimal points.

How do I combine these two things into one validation statement that does both?

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
May 16, 2019

So the percent formatting is setting the output to 0.0% when the output is blank or 0. That's just how it works. If you want something different then you need a custom format script.

Also, it is a really bad idea to change the field value in the validation script. So the user enters 44 for 44%, which is what I think you are trying to do, then the validation script changes the field value to 0.44. Now when the user clicks on the field the value is not 44, it's 0.44. How do they know what to do to change the field value? If they change it to 0.5, then the validation script will change it to 0.005.

A custom formatting script will also fix this.

For example:

event.value = event.value + "%";

That's all you need.

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
try67
Community Expert
Community Expert
May 16, 2019

It's important to note, though, that if you do it like that it doesn't guarantee that the input is a number. For example, they can enter "---" and it will accept it (and add the percentage symbol at the end).

KristiD5
KristiD5Author
Participating Frequently
May 16, 2019

Good callout.  Thanks!