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

adding text and a dollar sign to a custom format text field

Participant ,
Apr 25, 2019 Apr 25, 2019

Copy link to clipboard

Copied

I'm trying to add a script to the custom format window of a text field so I can have the results show like this - $22.33 per foot (or whatever dollar amount entered). I've been playing around with this bit of code but cannot get it to do as I want. Can someone help me out? Here's the javascript that comes close

AFNumber_Format(2,0,0,0,"$/ per foot",false);

TOPICS
Acrobat SDK and JavaScript , Windows

Views

2.7K

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
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 25, 2019 Apr 25, 2019

Try this:

if (event.value) {

    event.value = "$" + util.printf("%,0.2f", event.value) + "/ per foot";

}

Votes

Translate

Translate
Community Expert ,
Apr 25, 2019 Apr 25, 2019

Copy link to clipboard

Copied

What's the issue? It works fine for me, except the dollar sign appears after the number, instead of before it, but there's not much you can about that, unless you write your own Format script.

Votes

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
community guidelines
Participant ,
Apr 25, 2019 Apr 25, 2019

Copy link to clipboard

Copied

yeah, that's what it does for me as well. But, I don't want the dollar sign after the number. I thought it would be possible and an easy thing to do. I can get the script to do one way or the other. But, I cannot figure it out, how to get it to write the correct way I'd like.

Votes

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
community guidelines
Community Expert ,
Apr 25, 2019 Apr 25, 2019

Copy link to clipboard

Copied

Try this:

if (event.value) {

    event.value = "$" + util.printf("%,0.2f", event.value) + "/ per foot";

}

Votes

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
community guidelines
Participant ,
Apr 25, 2019 Apr 25, 2019

Copy link to clipboard

Copied

So right on. That's why they pay you the big bucks. I wouldn't have gotten it. Thank you, buddy. Hope you had a very nice trip.

Votes

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
community guidelines
Participant ,
Apr 27, 2019 Apr 27, 2019

Copy link to clipboard

Copied

Hi Gilad, I need your help again. I've been working with this script you provided, it works spot on. The one thing I noticed is it allows me to enter text as well. I don't want that, only the dollar and cents and per foot to show when a number is entered. I have been trying to find example thru the forum but there's nothing that will help. Could you show me how to restrict the field from accepting text? What I'm getting when I type text into the field shows like so - $jklm/ per foot. Ideally, the field should be blank if I try to enter text.

Votes

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
community guidelines
Community Expert ,
Apr 27, 2019 Apr 27, 2019

Copy link to clipboard

Copied

You would need a custom Keystroke script to do that.

Votes

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
community guidelines
Participant ,
Apr 27, 2019 Apr 27, 2019

Copy link to clipboard

Copied

Do you mean to place the script you provided into the Custom Keystroke window? Or to modify the script itself then place it into the Keystroke window? If so, I wouldn't know how do that. Would you have an example handy?

Votes

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
community guidelines
Community Expert ,
Apr 28, 2019 Apr 28, 2019

Copy link to clipboard

Copied

No, it's a different script. Try this:

event.rc = !isNaN(Number(AFMergeChange(event)));

It's possible that this script and the Format script will disappear after you enter it. That's OK. Just press Close and it should still work.

Votes

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
community guidelines
Participant ,
Apr 28, 2019 Apr 28, 2019

Copy link to clipboard

Copied

You make it look so easy. This was driving me nuts and I could not find anything that would help in the forum or the internet. I spent hours looking and trying things without any luck. Thank you for ALLLLL your help.

By the way the script did disappear as you said. What happened to it? What to do if I need to edit it? Would I just re-insert it like the start?

Votes

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
community guidelines
Community Expert ,
Apr 28, 2019 Apr 28, 2019

Copy link to clipboard

Copied

LATEST

You're welcome.

It disappears because it uses an internal function (AFMergeChange) and the application is set to display one of the built-in Format options when you do that. The code can be accessed via Edit All JavaScripts, but I recommend you don't edit it through there. If you need to edit it then re-apply the new code.

Votes

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
community guidelines