custom text box

I am creating a fillable document and have several text boxes that I would like to fill in a symbol if they are used. I would like to set it up simular to how you would have a number format in a text box where it adds a $ to the begining of each number but the box is blank without anything filled in. I have some boxes that I would like to put the "degree" sign in and a few that I would put "PSI" after the number.

I am new to these documents so the simpler way the better, please.

Doug Sanders

4 Answers

Voted Best Answer

This is achieved with a custom format script (Properties - Format - Custom - Custom Format Script), which changes the way a value looks, but not the actual value.
For example, this script will add " PSI" at the end of the entered value (if it's not blank):

if (event.value) event.value += " PSI"

Visit my custom-made PDF scripts website:
Contact me personally:

By Gilad D (try67)   

Have you looked at how the Number and Percentage fields store a value and display a value?

If you select the Number format and a currency symbol for a US Dollar and 2 decimal places and enter 10 into the field the display is $10.00 and the value of the field is 10. So the displayed value is realted to the value, but the value does not take on the display format. If one uses the custom format scirpt, then you can make the display field anything you want and not affect the field value for the field or any access to the field's value.

If you look at or have access to older Acrobat JavaScript documentation, Acrobat JavaScripting Guide Vesion 6, you could see there are some built-in script functions that can control formatting and keystrokes. Or you could use the util.printf or util.printx methods to create a display format.

The problem then becomes the keystroke and validation scripts needed for the numeric input. If the fields are the result of a calculation, you can leave the field as text field and then set the format as part of the calculation or in the Custom Format option.

Complete control could be achieved through the use of the RegExp object to design custom keystroke, validation, and formatting scripts.

For a division calculation using the US dollar and not showing the "$0.00" for a blank form one could set the field format to "None". The calculation script for the field could be:

event.value = ""; // clear the field
AFNumber_Format(2, 0, 0, "", "", false); // set field to number 2 decimal places
var cField1Name = "Divisor";
var cField2Name = "Dividend";
// get the values for the field names
var fName1 = this.getField(cField1Name).valueAsString;
var fName2 = this.getField(cField2Name).valueAsString;
if(fName1 != "" && fName2 != "") {
event.value = 0;
if(fName1 != 0) {
event.value = fName2 / fName1; // perform the calculation
AFNumber_Format(2, 0, 0, "", "$", true); // set field to number 2 decimal places $ currency prepended

George Kaiser   

If you want the answer formatted and rounded then you need to use the util.printf method.

if (event.value != "") {
event.value = util.printf("%,0 0.2f PSI", event.value); // display PSI to 2 decimal places

George Kaiser   

Worked perfect. Thank you for the quick responses.

Doug Sanders   

Please specify a reason: