Highlighted

Combining text and number fields without loosing number field format.

Community Beginner ,
Aug 20, 2020

Copy link to clipboard

Copied

In my job function I have to combine fields to generate letters for different departments. I can usually cobble together a working form, but in this case I'm hitting a wall. I'm trying to combine a text field with a number field without loosing my number field formatting.

 

Example: The following results in "The cost is 1000" while I am trying to get "The cost is $1,000.00"

var cost = "The cost is ";
var OS = this.getField("Old Salary").value

event.value = cost + OS;

 

 

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

61

Likes

Translate

Translate

Report

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

Combining text and number fields without loosing number field format.

Community Beginner ,
Aug 20, 2020

Copy link to clipboard

Copied

In my job function I have to combine fields to generate letters for different departments. I can usually cobble together a working form, but in this case I'm hitting a wall. I'm trying to combine a text field with a number field without loosing my number field formatting.

 

Example: The following results in "The cost is 1000" while I am trying to get "The cost is $1,000.00"

var cost = "The cost is ";
var OS = this.getField("Old Salary").value

event.value = cost + OS;

 

 

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

62

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 20, 2020 0
Adobe Community Professional ,
Aug 20, 2020

Copy link to clipboard

Copied

If this is just to display an output (not to be calculated any further with other fields), then You can use custom calculation script with arbitraty mask using the "util.printx()" method

 

Use it like this :

 

var v = this.getField("Old Salary").value;
v = util.printx("$9,9999", v);
event.value = "The cost is " +v;

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 20, 2020 0
Community Beginner ,
Aug 21, 2020

Copy link to clipboard

Copied

This is great! Is there a way to format it if the number of digits isn't fixed? In the above example the "$10,000" comes out as "$1,0000".

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 21, 2020 0
Engaged ,
Aug 21, 2020

Copy link to clipboard

Copied

Just move comma from this $9,9999 to this $99,999 but be warned then it won't show 1,000 it will show 10,00

 

EDIT: If you want to show both 1,000 and 10,000 replace this line: v = util.printx("$9,9999", v);

with this: v = util.printf("$%,0.0f", v);

If you also want to add decimal,replace second zero with number of desired decimals.

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 21, 2020 0
Community Beginner ,
Aug 21, 2020

Copy link to clipboard

Copied

This worked exactly as I wanted. Thanks!

 

var v = this.getField("Old Salary").value;
v = util.printf("$%,0.2f", v);
event.value = "The cost is " + v;

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 21, 2020 1
ls_rbls LATEST
Adobe Community Professional ,
Aug 21, 2020

Copy link to clipboard

Copied

Hey Jason!

 

Glad that this helped. Don't forget to mark NesaNurani's answer as correct solution, thank you.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 21, 2020 0