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

Placeholder text with a formatted number

Explorer ,
Apr 05, 2021 Apr 05, 2021

Copy link to clipboard

Copied

All of the placeholder text I worked with in form fields has relied on a custom format script, but now I want to have a placholder of 0 for a field I want to be formatted with a currency symbol and commas (but no decimal points). If I use the custom format to achieve the placeholder with an if/else event.value, what code can I add to it to format the text with a dollar sign, commas and no decimals? I suspect it involves util.printf but I'm a little stuck as to how to actually write it.

TOPICS
JavaScript , PDF forms

Views

1.1K

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 06, 2021 Apr 06, 2021

Again, you don't need to mess around with a custom Format script. It's not needed.

You just need to use the On Focus and On Blur events.

Votes

Translate

Translate
Community Expert ,
Apr 05, 2021 Apr 05, 2021

Copy link to clipboard

Copied

Do you mean that you want to format the value if it's not "0"?

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
Explorer ,
Apr 05, 2021 Apr 05, 2021

Copy link to clipboard

Copied

I want to have a placholder that reads "$ 0" and then when text is entered, I want it to read as "$ 1,000,000"

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 05, 2021 Apr 05, 2021

Copy link to clipboard

Copied

Just set the default value as "0", then, and use the built-in Number format setting... You don't need any scripts.

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
Explorer ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

I did that at first, but it leaves a 0 in the field when you click in and I'd prefer to have it disappear so the user doesn't have to either delete it or account for it in their entry.

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 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

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
Explorer ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

I've used this precise resource before, it's helped me many times! However, I can't figure out how the code will support both the disappearing text AND formatting the number in the way that I would like inside of the custom 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
Community Expert ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

The formatting is done by the option you select in the Format tab. You don't need to do it the 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
Explorer ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

But if I use a custom format script in the format tab in order to achieve the placeholder text, I can't also use currency formatting, correct? Or am I massively missing something?

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 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

Again, you don't need to mess around with a custom Format script. It's not needed.

You just need to use the On Focus and On Blur events.

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
Explorer ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

LATEST

Holy MOLEY, I hadn't noticed that the On Focus/On Blur part controlled anything beyond the color (which I don't need here, so I had been ignoring that bit). Thank you so very much for your patience, that is a much less hectic way to set up the field than using a util.printf to achieve formatting that is already built-in.

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