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

Entering Javascript in Text Field Properties

fjcunninghamjr
Registered: Oct 31 2006
Posts: 25

Hi,

I have already created a form for text to be entered. Now I am trying to tweak it to when a field is completed the text is changed to Upper Case. I can't seem to find or get to the Text Field Properties dialog to enter the action. Can someone take my throught the steps.
Frank

konsta
Registered: Jul 26 2006
Posts: 8
When you create a text field in Acrobat, the default name for the field is Textn where "n" is the integer representing the number of text fields on the form (for example, the first text field would have the default name Text1).

It sounds like you want the text entered into that field to be converted to all upper case when the user finishes entering text (usually by clicking on the next field or some other part of the screen).

One way to achieve this is to edit the properties of the text field you created (select the "Select Object" tool, which looks like a blue arrow on the Advanced Editing toolbar in Acrobat 8, then click on the field you created to select the field and then right click (in Windows) to get the options, then select Properties, which is at the bottom of the list).

The window that opens will have seven tabs, under the first tab "General", you will see the name for the field that you are working on. You need the correct name to make the next step work. In the code below, I will assume the name is Text1.

After you have the field's name, you then click on the Actions tab. You select the trigger "On Blur" in the first drop down and then select "Run a JavaScript" in the second drop down. You then click on the "Add" button. This will open up a JavaScript panel, where you type the following:

var strText = this.getField("Text1").value ;
strText = strText.toUpperCase() ;
this.getField("Text1").value = strText ;

You will, of course, need to replace "Text1" with the appropriate field name, but this should work.

You could do this all in one line by typing:

this.getField("Text1").value = this.getField("Text1").value.toUpperCase();

but I have found that when you are starting with JavaScript, it is often easier to break complex steps down to get the functionality working and do the shorter versions when/if you get it working. The longer version is easier to debug if you happen to make a typo somewhere.

I hope that helps.

---Andrew
fjcunninghamjr
Registered: Oct 31 2006
Posts: 25
In Designer when I click the Select Object tool, then click on the desired field, then right click I do not get the options that would take me to Text properties.
How is this done. I understand I must have the text properties dialog to add the javascipt, but I can't seem to get to the part. any help
Frank
konsta
Registered: Jul 26 2006
Posts: 8
Sorry, I didn't realize you were in Designer. After you have selected the field, you can enter scripts and calculations via the Script Editor (look under the Windows menu to make sure that you have the Script Editor checked, it should appear at the top of the screen between the menu bar and your form. On the far left you will see a drop down which allow you to select the action that will trigger the script/calcuation, to the far right there are two other drop downs that allow you to choose the scripting language and where the scripting resides (I believe the default is client). Between the drop down boxes is a text box where you can enter your script. There is a great deal of additional functionality in Designer with respect to scripting, but the javascript is essentially the same.

Does that get you where you want to go?

---Andrew
fjcunninghamjr
Registered: Oct 31 2006
Posts: 25
Following the instructions for Designer I am able the enter script in the Script Editor, but not sure which event action needs to be activated.
Frank
konsta
Registered: Jul 26 2006
Posts: 8
I believe you want to use te On Blur event, which triggers when the user leaves the field (or more accurately, when the field looses focus, which can occur when the user clicks on another field or clicks anywhere else so that the field is no longer selected). Why don't you give that a try and see if it works in the context of your application. My only hesitation is that I'm not sure if you want the user to have a chance to see the modified text, in which case, you might want to think about what happen if the user clicks on submit (which should trigger the JavaScript, but the user might not see it and they definitely wouldn't get a chance to modify it.

---Andrew