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

Text field: Add sequential numbers after text

Guest
Jun 28, 2016 Jun 28, 2016

Hello,

I am working on a form using Acrobat XI Pro. I need to populate one of my fields (called Order) with something similar to an invoice number, where I have several letters followed by a number that would need to increment by 1 when clicking on a button:

VS001

VS002

VS003...

I already have a button that increments said number; what I would like to know is how to precede it with (unchanging) letters.

The code for that button is:

this.getField("Order").value = Number(this.getField("Orden").value) + 1; 

Right now I am using two adjacent fields where one holds the letters and the other has the sequencing numbers, but I encountered the following problem:

- Numbers don't show any leading zeros (it shows as VS4 instead of VS004)

I'd like a more elegant solution where only one field would be needed, if possible.

How could this be achieved?

Thank you kindly.

TOPICS
Acrobat SDK and JavaScript , Windows
834
Translate
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 , Jun 28, 2016 Jun 28, 2016

You can use something like this:

var text = this.getField("Order").value;

var str = "000" + (Number(text.substr(-3))+1);

this.getField("Order").value = text.substr(0, 2) + str.substr(-3);

Translate
Community Expert ,
Jun 28, 2016 Jun 28, 2016

You can use something like this:

var text = this.getField("Order").value;

var str = "000" + (Number(text.substr(-3))+1);

this.getField("Order").value = text.substr(0, 2) + str.substr(-3);

Translate
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
Guest
Jun 29, 2016 Jun 29, 2016

Thank you. Could you please ellaborate? It's not working for me and, since I don't understand much about javascript, I don't quite get the meaning of the lines, so I don't know where I'm wrong.

I'm guessing you're setting properties for both text (limiting it to 2 characters, although I don't understand what the 0 in (0,2) means) and numbers (formatting it to 3 digits and adding 1 each time), and then making the field show as text+numbers.

Should I format the field in any way?

Translate
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
Guest
Jun 29, 2016 Jun 29, 2016

Okay, I got it working. I deleted the text that was showing and added VS000 to the default value in the field, now the button works correctly. Still, I would want to know what those lines mean.

Thanks again.

Translate
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 ,
Jun 29, 2016 Jun 29, 2016

You can learn how this (and other) method works here: JavaScript String substr() Method

Translate
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
Guest
Jun 29, 2016 Jun 29, 2016
LATEST

Thanks, I understand now .

Translate
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