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

Automatically create a "mailto" link when email address is typed?

nerdaggro
Registered: Mar 16 2010
Posts: 12
Answered

Hello! I hope someone out there can help with scripting this.

I have a one-line text field for entering an email address. I need to know how it will automatically turn that email address into a "mailto" link after the user has entered the information or moved on to the next field.

Thank you!

My Product Information:
Acrobat Pro 8.1.7, Windows
jimhealy
Team
Registered: Jan 2 2006
Posts: 146
getURL("mailto:" + getField("myTextFieldName").value);
Of course, you would put this in a button probably and you would want to validate the e-mail address and you would probably also want to check that the e-mail address was not blank before you let the code run.

Jim Healy
FormRouter, Inc.
Check out our FREE Advanced Acroform Toolset:
http://www.formrouter.com/tools

Jim Healy, Founder & CEO FormRouter Inc.
Chapter Leader AUG RTP NC
http://www.formrouter.com

nerdaggro
Registered: Mar 16 2010
Posts: 12
Thanks, it looks close. But I don't want to tie this to a button.

Basically, whatever they type should be turned into a link once they hit return/enter or tabbed to another field:

Email: myname [at] myemail [dot] comTO

Email: [u]myname [at] myemail [dot] com[/u]Make sense? Thanks!
jimhealy
Team
Registered: Jan 2 2006
Posts: 146
Do you want them to be able to edit it again afterword? The only thing I can think of would be on blur, set the field to readonly, set it to support Rich Text, make a span out of the text, set the span to the color you want and underlined.

After that you could either:
1. Add a link to the page with the same rectangle as the field, then set the javascript on the link to what I wrote earlier. The problem with this is that you can't do it in Reader.
OR
2. If you need it to work in Reader, then you would need to add the script I gave you above to the Mouse Up action and not set the field to read only and check that the e-mail is filled in before launching.

Jim Healy
FormRouter, Inc.
Check out our FREE Advanced Acroform Toolset:
http://www.formrouter.com/tools

Jim Healy, Founder & CEO FormRouter Inc.
Chapter Leader AUG RTP NC
http://www.formrouter.com

nerdaggro
Registered: Mar 16 2010
Posts: 12
Thanks, Jim! That was very helpful. There are still some things I need to resolve, but here's what I did so far:

Actions: Mouse Down > Run a Javascript
Code: getURL("mailto:" + getField("myTextFieldName").value);

I tried Mouse Up and On Blur at first, but doing that opens a new message with their default mail client when you tab to the next field or when you mouse over the field. I only need to launch the script after the email has been validated and only when they click on the text.

Selecting Mouse Down as a trigger works fine, except it still opens a new message even if the field is blank. One more thing, I still can't figure out how to style the block of text being entered as underlined.

Thanks!
jimhealy
Team
Registered: Jan 2 2006
Posts: 146
You just need an if statement to check for your condition.

As far as the Span goes, check out the Javascript reference guide. There is an example of exactly how to do that.

Jim Healy
FormRouter, Inc.
Check out our FREE Advanced Acroform Toolset:
http://www.formrouter.com/tools

Jim Healy, Founder & CEO FormRouter Inc.
Chapter Leader AUG RTP NC
http://www.formrouter.com

nerdaggro
Registered: Mar 16 2010
Posts: 12
Gotcha. I think I've got it. Jim, thanks for helping out! In case others need to know what I did, here it is.

Quote:
[b]Options:[/b] Allow Rich Text Formatting[b]Actions:[/b] Mouse Down > Run a Javascript
if(this.getField("myTextFieldName").value != ""){getURL("mailto:" + getField("myTextFieldName").value);}

[b]Format:[/b] Select Format Category > Custom, Custom Options > Custom Format Script
var spans = event.richValue;for ( var i = 0; i < spans.length; i++ ){spans[i].underline = true;spans[i].textSize = 8;}event.richValue = spans;
FYI: This email field was replicated in other pages of my form. In order to keep the "mailto" link functionality consistent in all of these fields, make sure you add the Actions Javascript on those fields as well.

There's one problem with this that I couldn't crack, though. Originally, the text size was on Auto and I set a character limit to each field to make sure the font didn't run too small. Setting the textSize to 0 or Auto didn't achieve the same effect. I was always limited to the size of the text field. It's not that important to get a solution to this, but if anyone knows how, please post.

Thanks again!