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

Button label value - drawing from a text field

David Dunn
Registered: Oct 28 2010
Posts: 116
Answered

I am looking for a technique to change the label on a button to match a value in a text field. The value in my text field will vary from user to user. The button label needs to match the text field value of the individual user.
 
I would be grateful for any solutions. Thank you so much.
 
DavidD

David D

My Product Information:
Acrobat Pro 9.4, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Accepted Answer
You need to use a custom JavaScirpt. When do you want this action to occur?

You can get the 'value' property of the text field and set the button label with the 'buttonSetCaption' method. See the example under the 'Field' object, 'Field methods', 'buttonSetCaption' in the Acrobat JS API Reference.


George Kaiser

David Dunn
Registered: Oct 28 2010
Posts: 116
Thanks once again George. That works great. I set the script as an "On blur" action in the source text field. When the user enters a value and tabs out of the text field, the script changes the button label (aka "caption"). I was looking for something under the word "label" in the API Reference, not knowing that "caption" is synonymous.

For the benefit of others, here's what works for me:

var source = this.getField("txt.Township.Name")
var target = this.getField("btn.Page5.Township")

target.buttonSetCaption(source.value)

David D

RogerOno
Registered: Dec 21 2010
Posts: 3
George or David,

Is it possible to use buttonsetcaption to dynamically "name" buttons using values passed to the form from Itext?
David Dunn
Registered: Oct 28 2010
Posts: 116
Roger, I'm not sure what you mean by values passed to the form from [?]text, so I can't be of help except to say in my case, whatever value I enter in my text field is picked up as the caption for my button.

David D

RogerOno
Registered: Dec 21 2010
Posts: 3
Thanks for responding so quickly David. I'm new to Acrobat Forms and I'm not the best at Javascript -- so I'm probably not asking my question correctly.

I have a form that is dynamically populated from an Access Database via Itext. One of the fields is indeed a hidden text field named "user" Please remember there is no "event" like onclick or onblur to trigger the whole thing like in your example.

Question is, How can I use the value of "user" to create a button lable on the same page named "export"?

Thanks,
Larry

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
This is really an iText question, so you might check its documentation to see if there's a method for setting the label of a button. If there is, you'd do this at the same time that you're setting the field values.

A less than ideal alternative is to set up a document-level JavaScript in Acrobat that copies the value of the field to the label of the button each time the document is opened. This is the event that would trigger things. It would look something like:

// Set button label from value in a text field
getField("button1").buttonSetCaption(getField("text1").valueAsString);
David Dunn
Registered: Oct 28 2010
Posts: 116
Preliminarily, I am pretty much in the same boat as you so far as my experience level.

I do however have a solution for you, but only IF you can substitute a text field for your button field. I use this successfully in my form. The happy discovery is that custom calculations can be used to achieve your objective. Button fields don't accommodate calculations, so you need to use a text field or combo box field.

Custom calculations (a) don't require an event to trigger them and (b) can be used to bring in text as well as to perform math on numbers. For example, let's use 2 text fields, one called the 'source' and the other the 'recipient' field.

The recipient field's format should be set as "none" on the properties format tab. If you set it to a number format and your source field is providing text, it won't work; the recipient field format must be set to "none" to use a calculation to bring in text from a source field.

In your recipient field properties go to the "Calculate' tab, choose "Custom calculation" and then enter the following java script (substituting your field names for mine:

var sourceField = this.getField("yourSourceField")
event.value = sourceField.value

Close out the properties dialog box and try it out.

I also successfully use this technique when the source field format is set to a phone number format and the recipient field is a text field with format set to "none." Here is how I set up that script:

var sourceField = this.getField("sourceFieldPhoneNumber").value
event.value = util.printx('999-999-9999', sourceField)

Finally, if you are not aware of it, with the exception of the great help I get on this web site, I learned everything I know in the book 'Extending Acrobat Forms With Java Script' by John Deubert. I highly recommend it if you can find it (it is a few years old). You might find it at John's web site, acumentraining.com

DavidD








David D

RogerOno
Registered: Dec 21 2010
Posts: 3
Thank you George and David, with your help, it now works exactly as needed!! Now on to the next challenge, having the form emailed based on a selection from a dropdown list. Any help would be greatly appreciated.
Larry
David Dunn
Registered: Oct 28 2010
Posts: 116
Larry, your next challenge is too complex to answer here. In the book I recommended by John Dubert, 'Extending Acrobat Forms With Java Script' there is an entire chapter on combo boxes and triggering certain reactions to export values assigned to items in the combo box. If you can get your hands on that and study it then you can probably determine how to accomplish your objective.
David

David D

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
If you set the export values of the combo box items to the corresponding email address, you can get the combo box field's value and use it with a mailDoc or submitForm statement. There are a lot of examples of doing this in this forum. Here are links to the documentation for those methods:

mailDoc: http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.505.php

submitForm: http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.537.php