These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Numbering a field

Anonymous
Answered

I have a text field called "ref". Is it possible to assign a script to it so when the document opens the number inside the field increases by one?

For example the the very first document opened will be ref001, and then followed by ref002 etc

I have already set a field up for automatic date entry that i found with this code
var f = this.getField("Ref")
f.value = untilprinted
("m, ,d, yyyy', new date());

I've been trying to enter the following code some where
var newNum = Number(num) + 1;

but cant get it to work at all!

Can anybody please stear me in the right direction

Thank you very much

My Product Information:
Acrobat Pro 9.1.3, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2399
The script needs to be attached to the *document*, not the field itself.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

smitchell15 (not verified)
Hi try67, thanx for the reply, i've got the first script working for the date entry by attaching that code into the pages actions and that worked a treat, the script i'm having problem with tho is the automatic number of the "Ref" text field. I've entered this following code but its not working yet!

var f = this.getField('ref");
var newNum = Number(num) + 1;

even tried this!
var f = this.getField('ref");
event.value = Number(num) + 1;

And this...
var f = this.getField("ref");
var newNum = Number(num);
f.value = var newNum + 1;

And finally this...
var f = this.getField("ref").value;
var newNum = Number(num);
f.value = Number(num) + 1;

As you can probably see! I'm still very new to this! Can you give me some more advice please on what extra code i could need to get this to work please. I think this line should be used
var newNum = Number(num) + 1;
but I know if i need to put it in a document script that i need to reference the field such as
var f = this.getField("ref");

But not sure how i can link them together!!

Any more help would be greatly appreciated.

Thanx
try67
Expert
Registered: Oct 30 2008
Posts: 2399
Where is the definition of "num"? Why not simply something like:

this.getField("ref").value = this.getField("ref").value+1;

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

smitchell15 (not verified)
Thats brilliant, thankyou, easy as that!

One last thing tho, if i want to add say 6 zeros at the beginning such as 0000001, and the next one would be 0000002, is that easily done as this script only works if i start off with 1. If i put 0000001 in the field, the next number just returns 2.

If not nethermind as i'm very happy and greatful for that script

thankyou