SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Dec 2008
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question create an e-mail button

    I'm trying to create an e-mail button using HTML. In the book I'm using to learn HTML the tag there using is:

    <button onclick="location.href="'mailto:sales@hrmusainc.com?subject=address change'">send an address change</button>


    The button shows up but it does not work can anyone please tell me how to do this?

  2. #2
    SitePoint Guru Ize's Avatar
    Join Date
    Nov 2005
    Location
    The Netherlands
    Posts
    808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is a double quote in the Javascript bit that ends the attribute value:

    Code:
    <button onclick="location.href="'mailto:sales@hrmusainc.com?subject=address change'">send an address change</button>
    On another note; why don't you use a regular link? It's more semantic, Google can read it, and it works when Javascript is off;

    Code:
    <a href="mailto:sales@hrmusainc.com?subject=address change">Send an address change</a>

  3. #3
    billycundiff{float:left;} silver trophybronze trophy RyanReese's Avatar
    Join Date
    Oct 2008
    Location
    Whiteford, Maryland, United States
    Posts
    13,564
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)
    Use a link and you can style it like a button:
    Code:
    <a href="mailto:sales@hrmusainc.com?subject=address change"><div>Send an address change</div></a>
    ...
    a{display:block;border:1px solid black;}
    div{background:blue;color:black;}
    Twitter-@Ryan_Reese09
    http://www.ryanreese.us -Always looking for web design/development work

  4. #4
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you don't want to follow the advice from Ize and RyanReese, for some reason, you need to remove the extraneous quotation mark from your attribute value.

    Code HTML4Strict:
    <button onclick="location.href='mailto:sales@hrmusainc.com?subject=address change'">send an address change</button>
    Birnam wood is come to Dunsinane

  5. #5
    SitePoint Zealot FaridHadi's Avatar
    Join Date
    Nov 2008
    Posts
    170
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you are just learning it's fine and you can try both the options above. Just be aware of the fact that if you use this on a live site you'll be receiving a lot of spam, as you are typing out your email address in the source code.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •