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

Turning user-entered text into an active hyperlink

SLDC
Registered: Oct 25 2010
Posts: 70
Answered

I've got a field for the location of a file associated with the form. I'd like the users to be able to enter the location's URL as text, and have the form turn that into a clickable hyperlink, just as if I'd used LiveCycle Designer's "insert hyperlink" function. Is this possible with JavaScript? The scripting reference only talks about Designer's internal hyperlink addition/modification.
 
Just for reference, the links are to files in SharePoint spaces. Unfortunately, none of my users have/will have Acrobat X anytime in the near future, so none of X's SharePoint integration features will help.
 
Thanks,
SLDC

My Product Information:
LiveCycle Designer, Windows
radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
Accepted Answer
Hi,

it is possible to create links of text inputs via scripting, but it's not that easy.
You generally have to allow RichText entries for your textfield.
Then you can use XHTML statements to create a hyperlink from the input.

Here's an simple example file that will do this.
https://acrobat.com/#d=3dunFuU2zL9MQg*j-PZpAQ

But, there are many things unsolved.
There is no control of how the link is written, so the hyperlink can point to an invalid destination.
Also, the whole text is converted to a hyperlink.
If you only want to convert a portion of the text, then you have to extend the scriptings.

So, you better choose the build-in way.
If your set up your text fields for rich text, you can highlight the portion of the text you wanna convert into a hyperlink.
Then click right and select "Hyperlink" from the context menu.
There you can add the URI to you destination and the app does the rest for you ;-)

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

SLDC
Registered: Oct 25 2010
Posts: 70
Thanks, Radzmar. The method in your sample file works beautifully.

SLDC
SLDC
Registered: Oct 25 2010
Posts: 70
Radzmar,
A user has pointed out to me that my version of the code you supplied isn't working in Acrobat 8 Std; I've also now tested it in Acrobat 8 Pro and it doesn't work there either. I hadn't noticed this because your method works fine in Reader 9 & 10 and Acrobat 9 Pro. Unfortunately, my user population is working in version 8 Std, without the option of an upgrade any time soon, and it isn't feasible for them to use Reader just for this form.Can you think of a reason why 8 can't handle this? I don't have access to LiveCycle Designer 8.1 anymore, but it seems to me that the exData object and .loadXML should still have worked.

Thanks,
SLDC


Your relevant code, in a button's Click event, was:

if (xfa.host.name != "XFAPresentationAgent"){var oURI= xfa.resolveNode("Formular1.#subform.TextField1").rawValue;var oLink = "<body xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:xfa=\"http://www.xfa.org/schema/xfa-data/1.0/\"><p style=\"letter-spacing:0in\"><a href=\"" + oURI+ "\" style=\"margin-top:0pt;margin-bottom:0pt;text-valign:middle;font-family:'Myriad Pro';font-size:10pt\">I'm a Hyperlink</a></p></body>"xfa.resolveNode("Formular1.#subform.TextField1").value.exData.loadXML(oLink, false, true);}
willin2u
Registered: Sep 14 2009
Posts: 16
Everything I have read so far confirms that Adobe is not capable of allowing a document user to insert a hyperlink as in Microsoft Word where you simply cut and paste and press enter and it is a hyperlink.

I too tried radzmar's solution and it does not work in Acrobat 8 which is used in our company. It does work in Acrobat Adobe 9 Pro though.

Does anyone have a javascript solution that would be compatible with LiveCycle Designer and give you similar results as Microsoft Word (i.e. cut and paste and press enter and it is a hyperlink)?

radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
I do not work with Acrobat/Reader 8.0 anymore so I cannot say if or why my previous solution does not work.
But, you can try out the build in functions for rich text fields to create hyperlinks manually.

1. Create a text field which allows rich text input
2. Open the form in Acrobat/Reader and enter something into the text field
3. select the part of the text that should be turned into a hyperlink
4. right click the field and select "Hyperlink"
5. enter the URI for the hyperlink and press "ok".
6. The selected part in the text field is then turned into a hyperlink.

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

willin2u
Registered: Sep 14 2009
Posts: 16
Yes but I am trying to allow the use to copy and paste an http address into the form and by doing so it retains the hyperlinked information. Do you know how this can be done?

How about HTML code for the hyperlink? Is that possible in a LiveCycle form?