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

How to extract part of Text Field String

dol303
Registered: Mar 26 2008
Posts: 8

Hello,
I am using livecycle 8 and want to know how to extract part of a text field input.

for example, when a user types in a four digit year, I want to populate another field that is designed for only two characters (type in "2004" in year field; another field is populated with "04".

I have attempted to use the substring method but it is not working for me.

Also, can substring methods be used when creating forms with livecycle"

Thanks in advance.

My Product Information:
LiveCycle Designer, Windows
almitche
Expert
Registered: Apr 1 2008
Posts: 41
Hi there,

There are a few ways to do this. Here's one involving FormCalc...

Imagine this kind of object hierarchy:

TextField1
TextField2

Both object exist at the same level, relative to one another. Now, you can add the following FormCalc script to the calculate event of TextField2:

Substr(TextField1.rawValue, (Len(TextField1.rawValue) - 1), 2)

It uses two useful FormCalc functions: Substr and Len. Substr has three inputs:

1) The string you want to extract from.
2) The starting position.
3) The number of characters to extract

I used the Len() function to get the number of characters in the value of TextField1, and then subtracted 1 to get the starting position. That makes sense if you remember that you want to grab the 2 last digits. So for a value like:

2008

the Len() function returns 4, and 4-1 = 3, which is where I want to start extracting. I want digits 3 and 4 from the value.

You can do something similar with JavaScript:

var s = TextField1.rawValue;
s.substr(s.length-2,2);

In the case of JavaScript, you need to subtract 2 from the length because JavaScript begins parsing the string at the next position from where you tell it to start (as opposed to FormCalc that start at the position you tell it to start).

You can learn more about FormCalc functions in the Designer Help (hit F1 when Designer is running) in the section of Scripting.

Hope that helps.