Passing textbox value on coldfusion form to mailto tag

Discussion in 'Javascript' started by jnag, Dec 28, 2007.

  1. jnag

    jnag Guest

    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
    jnag, Dec 28, 2007
    #1
    1. Advertising

  2. jnag

    Doug Gunnoe Guest

    On Dec 28, 2:52 pm, jnag <> wrote:
    > 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:";
    }
    </script>
    </head>

    <body>

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

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

    </body>
    </html>
    Doug Gunnoe, Dec 28, 2007
    #2
    1. Advertising

  3. On Dec 28, 9:27 pm, Randy Webb <> wrote:
    > jnag said the following on 12/28/2007 3:52 PM:


    > > The outlook window pops up, but does not get populated with the
    > > email address. Can you please give me some suggestions?


    > Yeah, stop using the mythical mailto: protocol, it isn't reliable.
    > <URL:http://www.isolani.co.uk/articles/mailto.html>


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

    --
    David Dorward
    http://dorward.me.uk/
    http://blog.dorward.me.uk/
    David Dorward, Dec 28, 2007
    #3
  4. On Dec 28, 8:52 pm, jnag <> wrote:
    > 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.

    --
    David Dorward
    http://dorward.me.uk/
    http://blog.dorward.me.uk/
    David Dorward, Dec 28, 2007
    #4
  5. David Dorward wrote:
    > On Dec 28, 9:27 pm, Randy Webb <> wrote:
    >> jnag said the following on 12/28/2007 3:52 PM:
    >>> The outlook window pops up, but does not get populated with the
    >>> email address. Can you please give me some suggestions?

    >
    >> Yeah, stop using the mythical mailto: protocol, it isn't reliable.
    >> <URL:http://www.isolani.co.uk/articles/mailto.html>

    >
    > Mike's article, while excellent, discusses the use of mailto: as a
    > form action, not an anchor's href. Using
    > href="mailto:" 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
    --
    Anyone who slaps a 'this page is best viewed with Browser X' label on
    a Web page appears to be yearning for the bad old days, before the Web,
    when you had very little chance of reading a document written on another
    computer, another word processor, or another network. -- Tim Berners-Lee
    Thomas 'PointedEars' Lahn, Dec 28, 2007
    #5
  6. On Dec 28, 10:43 pm, Thomas 'PointedEars' Lahn <>
    wrote:
    > > Mike's article, while excellent, discusses the use of mailto: as a
    > > form action, not an anchor's href. Using
    > > href="mailto:" 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.


    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).

    --
    David Dorward
    http://dorward.me.uk/
    http://blog.dorward.me.uk/
    David Dorward, Dec 29, 2007
    #6
  7. David Dorward wrote:
    > [...] Thomas 'PointedEars' Lahn [...] wrote:
    >>> Mike's article, while excellent, discusses the use of mailto: as a
    >>> form action, not an anchor's href. Using
    >>> href="mailto:" 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.

    >
    > 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
    --
    var bugRiddenCrashPronePieceOfJunk = (
    navigator.userAgent.indexOf('MSIE 5') != -1
    && navigator.userAgent.indexOf('Mac') != -1
    ) // Plone, register_function.js:16
    Thomas 'PointedEars' Lahn, Dec 29, 2007
    #7
  8. On Dec 31 2007, 1:11 am, Randy Webb <> wrote:
    > > 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.


    > 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.

    > > A number of browsers even have explicit "Copy email
    > > address" functionality on the context menu, which gets around the
    > > issue of webmail clients

    >
    > 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).

    --
    David Dorward
    http://dorward.me.uk/
    http://blog.dorward.me.uk/
    David Dorward, Jan 3, 2008
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shruds
    Replies:
    1
    Views:
    707
    John C. Bollinger
    Jan 27, 2006
  2. André
    Replies:
    2
    Views:
    679
    André
    Jun 23, 2008
  3. Onnuri
    Replies:
    1
    Views:
    120
  4. Replies:
    3
    Views:
    202
    Dave Burt
    Mar 15, 2006
  5. Thomas Gagne
    Replies:
    2
    Views:
    305
    Robert Klemme
    Mar 15, 2013
Loading...

Share This Page