Passing textbox value on coldfusion form to mailto tag

J

jnag

Hi,

I have a text field on a coldfusion form in which the user
enters an email address. Next to the text field, there is a link
called "Email". If the user clicks this link, an outlook window
should popup with the email address from the text field
populated in the To field. The outlook window pops up, but
does not get populated with the email address. Can you
please give me some suggestions?

I am trying to do it this way:

<a href="mailto:javascript:document.mainInputForm.email_address.value"
target=""><b>Email</b></a>

Thanks,
jn
 
D

Doug Gunnoe

Hi,

I have a text field on a coldfusion form in which the user
enters an email address. Next to the text field, there is a link
called "Email". If the user clicks this link, an outlook window
should popup with the email address from the text field
populated in the To field. The outlook window pops up, but
does not get populated with the email address. Can you
please give me some suggestions?

I am trying to do it this way:

<a href="mailto:javascript:document.mainInputForm.email_address.value"
target=""><b>Email</b></a>

Thanks,
jn

jn,

Your way will not work. I guess you already knew that, huh?

Try this, give your link an id, take the string from your form, then
change the href attribute of your link.

Something like this:

var changeMail = document.getElementById('email_address');
var mailLink = document.getElementById('mailnk');
mailLink.href="mailto:" + changeMail.value;


and then the link would be <a href="mailto:some_email@some_place.net"
id="mailnk" />Click here </a>

Of course, you have to trigger the change with an event.

And, Randy's objections in this case are worth noting.

Here is an example of the concept:

<html>
<head>
<script>
function changeMail(){
var mx = document.getElementById('mailnk');
mx.href="mailto:[email protected]";
}
</script>
</head>

<body>

<input type="button" onclick="changeMail()" />

<a href="mailto:[email protected]" id="mailnk" />some email</a>

</body>
</html>
 
D

David Dorward

I have a text field on a coldfusion form in which the user

Coldfusion isn't involved in your example.
enters an email address. Next to the text field, there is a link
called "Email". If the user clicks this link, an outlook window
should popup with the email address from the text field
populated in the To field.


The following is garbage for a number of reasons:

* It doesn't work without JavaScript
* It doesn't work with webmail under most circumstances
* It is a pointless exercise in moving the To field from the email
client into the webbrowser - user's can just switch to the email
client.

That said, the following should, theoretically (I'm not going to test
this since its a pointless exercise), work (some of the time):

<form action="fallback.html" onclick="document.location='mailto:' +
this.elements.address.value; return false;">
<div>
<input name="address"><input type="submit" value="Email">
</div>
</form>

You can mitigate the issue of dependence on JavaScript by performing
an HTTP redirect to mailto: and then the address (this would require
something, such as Coldfusion, running on the server, at the URI
specified in the action attribute).

It is still a pointless exercise though. If you are trying to solve
the problem of people not knowing how to use their email client, then
train them, don't try to create an interface that, once learned, isn't
going to help them when they use a different system.
 
T

Thomas 'PointedEars' Lahn

David said:
Mike's article, while excellent, discusses the use of mailto: as a
form action, not an anchor's href. Using
href="mailto:[email protected]" is quite sensible.

Actually, it is almost as bad. For example, consider an Internet café where
there would be no local e-mail client be installed or if it was, most
certainly it was not configured or the configuration be allowed to be
changed. And if that example is too far-fetched for you, consider users of
GMail or other Web mail services which would seldom use a local MUA.


PointedEars
 
D

David Dorward

Actually, it is almost as bad. For example, consider an Internet café where
there would be no local e-mail client be installed or if it was, most
certainly it was not configured or the configuration be allowed to be
changed. And if that example is too far-fetched for you, consider users of
GMail or other Web mail services which would seldom use a local MUA.

While there are users who it won't work for, it doesn't cause effects
that are anywhere near as broken as that of trying to use it as an
action in a form. A number of browsers even have explicit "Copy email
address" functionality on the context menu, which gets around the
issue of webmail clients (as do tools such as
http://lifehacker.com/software/gmail/lifehacker-code-better-gmail-firefox-extension-251923.php
which make mailto links work with webmail clients). Additionally, a
mailto link that is formatted according to the usual conventions gives
strong enough hints that it wants to open in an email client that
relatively few users will be confused (unlike a form where there are
no conventions to indicate that it uses mailto).
 
T

Thomas 'PointedEars' Lahn

David said:
While there are users who it won't work for, it doesn't cause effects
that are anywhere near as broken as that of trying to use it as an action
in a form.

Yes, it does. While it would not cause the user to fill out a Web form and
then end up with an empty e-mail, it does cause users to write an e-mail
that eventually cannot be sent, without even an indication before they click
the `Send' button that this might happen. If, and only if, there is an
e-mail application installed *and* registered in the HTML user agent to
handle `mailto:' URIs.
A number of browsers even have explicit "Copy email address"
functionality on the context menu, [...]

I don't know any non-developer (and I know not few) who would be aware of
that feature. Besides, you jump to conclusions here.


PointedEars
 
D

David Dorward

One is just as broken as the other.

When a link is clicked, if it doesn't work, then it doesn't work.

When a form is submitted, if it doesn't work, then the work done in
entering the data into it is mostly wasted.

That's a significant difference.
Where can I find this in a context menu? In a default setting.

Firefox at the very least.
So, it is ok to use a broken mailto: link because people can use
additional software to get the functionality? Sounds like a good
argument for making scripting required on a website.

As mentioned, it will work just fine for most users, and doesn't cause
any significant problems for other users (who can copy/paste the
address).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,438
Messages
2,571,699
Members
48,796
Latest member
Greg L.
Top