Skip to main content
June 28, 2016
Answered

Text field: Add sequential numbers after text

  • June 28, 2016
  • 1 reply
  • 966 views

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.

This topic has been closed for replies.
Correct answer Bernd Alheit

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);

1 reply

Bernd Alheit
Community Expert
Bernd AlheitCommunity ExpertCorrect answer
Community Expert
June 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);

June 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?

June 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.