SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Oct 2004
    Location
    NYC
    Posts
    306
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How can I form email address via this function? Help please

    Hello,

    I would like to be able to pass two arguments via function:
    1. name
    2. email

    Then I would like to split the fullname into an array so I would have first and last name. then I would concat the firstname and lastname (firstname.lastname) then I would like to hyperlink the the name so if the user clicks on the name, email client pops open and prompts user for email. I have tried to write the function, but appreciate any help. I am very new to JAVASCRIPT so please forgive my poor code.

    PHP Code:
    function contactInfo(name,email)
    {
      var 
    domain "@yahoo.com";
      var 
    splitName split.name(" ");
      var 
    emailAddress splitName[0] + "." splitName[1] + domain;

     
    document.write("<a herf = 'mailto:' + emailAddress> + name + "</a>";


  2. #2
    SitePoint Guru Chroniclemaster1's Avatar
    Join Date
    Jun 2007
    Location
    San Diego, CA
    Posts
    784
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    are you wanting to construct an email address onscreen from what a visitor types in?

    are you trying to obfuscate addresses (hide the address from spammers)?

    or something else?
    Whatever you can do or dream you can, begin it.
    Boldness has genius, power and magic in it. Begin it now.

    Chroniclemaster1, Founder of Earth Chronicle
    A Growing History of our Planet, by our Planet, for our Planet.

  3. #3
    SitePoint Addict
    Join Date
    Oct 2004
    Location
    NYC
    Posts
    306
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Talking

    Hey Chroniclemaster1,

    Neither or nor. What I would like to do is to be able to make the fullname clickable so if a user clicks on the name, the email client pops open.

    So I have been able to take the users entered name and split it into an array. I have already assigned a variable to the domain name. I would want to write mailto: function within javascript by just placing the firstname . lastname and domain.

    Please see my code, I think I am on the right track but my code lacks.

    Thanks a lot.

  4. #4
    SitePoint Guru Ize's Avatar
    Join Date
    Nov 2005
    Location
    The Netherlands
    Posts
    808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code javascript:
     
    function contactInfo (name){
      var domain = '@yahoo.com';
      var names = name.split(' ');
      var email = names[0] + '.' + names[1] + domain;
      return email;
    }
     
    var email = contactInfo ("John Johnson");
     
    // email now contains "John.Johnson@yahoo.com"

    Something like this?

  5. #5
    SitePoint Addict
    Join Date
    Oct 2004
    Location
    NYC
    Posts
    306
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey Ize,

    Thanks a lot, I will give it a try.

    Thanks.

  6. #6
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    What about for those people who don't have an email client available eg. internet cafes, libraries etc.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  7. #7
    SitePoint Guru Chroniclemaster1's Avatar
    Join Date
    Jun 2007
    Location
    San Diego, CA
    Posts
    784
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice work, Ize.

    Hey felgall, I don't know of any way to send email from javascript, though I came at it from the same standpoint as you did. When I built a contact application for a client, I wanted it to be completely self contained. The upside is it works great, the downside is I did have to bail and do it server side. I used the ASP.NET mail classes and a little vb programming to take the input from a nicely CSS styled user form and convert it into a convenient and client friendly email message. But I literally think it's impossible to do that client side for the precise reason that the client side code can't control the server's access to email. And if you can't use the server's email channel, you have to open the client's email application like we're doing here.
    Whatever you can do or dream you can, begin it.
    Boldness has genius, power and magic in it. Begin it now.

    Chroniclemaster1, Founder of Earth Chronicle
    A Growing History of our Planet, by our Planet, for our Planet.


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
  •