#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    21
    Rep Power
    0

    mailto: <array> in Javascript?


    Hey,
    I want to email a list of people in an array when the link has been clicked. I am tryin to implement this in Javascript if possible.
    For easy reading and upgradability I have the array in a seperate file called "the_contact.js" which is read in when the page is loaded. So when the user clicks the link I want the mailto service to reference all the names in the array.

    var the_names=new Array()
    the_names[0]="Joe Bloggs"
    the_names[1]="Peter Pan"


    then in the main program

    <a href="mailto: the_names">Contact Us</a>

    I cant reference the variables individually as I wont know how big the array is at any one time! i.e the above array has only two entries, but what if another member joins the group?! I dont want to have to continuously go in and search for the mailto link and add his/her name in. So "the_contact.js" file is where I would add them.

    Any ideas on how I can implement this?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Location
    Bavaria, Germany
    Posts
    140
    Rep Power
    12
    If you want to send mails to multiple reciepent you have to use:
    <a href="mailto:Address1;Address2;Address3">Contact us</a>

    So all you have to do now is to change the location of your
    document to the string above containing all your items of your the_names array when a user clicks on the link.

    Solution:

    Code:
    var the_names=new Array();
    
    the_names[0]="Joe Bloggs"
    the_names[1]="Peter Pan"
    
    function getContactLink() {
      var str = "mailto:"
      for (var i = 0; i < the_names.length; i++) {
        str += the_names[i] + ";"
      }
    
      document.location = str;
    
      return;
    }
    ...and in your .html...

    <a href="javascript:getContactLink()">Contact Us</a>

    That's it ;-)
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    21
    Rep Power
    0
    Thanks Wingman! That works perfect!

    Can I pick your brains on the same matter only slightly different!

    I have a few contact lists so I would rather send a parameter to this function i.e

    function getContactLink(Contact_List) {
    var str = "mailto:"
    for (var i = 0; i < Contact_List.length; i++) {
    str += Contact_List[i] + ";"
    }

    document.location = str;

    return;
    }

    and call it by

    <a href="Javascript: getContactLink('the_names')">Contaqt Us</a>

    But when outlook opens the window the "to:" field is full of "undefined"

    Any ideas?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Location
    Bavaria, Germany
    Posts
    140
    Rep Power
    12
    <a href="java script: getContactLink('the_names')">Contaqt Us</a>

    You call the function "getContactLink" with the String "the_names", not the variable the_names ;-). Just leave out those ' and everthing should be fine :-)
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    21
    Rep Power
    0
    ahha yes. You're right again!

    Thanks Wingman! You've been a real help!

IMN logo majestic logo threadwatch logo seochat tools logo