SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru moonman's Avatar
    Join Date
    Dec 2000
    Location
    The Sea of Tranquility
    Posts
    696
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Populate Form Field

    This may well be very simple, so please forgive my lack of javascript knowledge.

    I've got a site which has a different email address on each page. What I need to do is, when someone clicks on the email address, it populates a text box on a different page with the email address that was clicked.

    Then, I need the form to submit an email to the email address that has been specified by clicking the link.

    Help please!!!

  2. #2
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Put the email address in the link's query string, like this
    <a href="differentpage.htm?email=xxx@yyy.zz">Send an email to xxx@yyy.zz</a>

    In differentpage.htm you can get the email with...
    var email = location.search.substr(location.search.indexOf('email=') + 6);
    ...and then put it in the text box...
    document.forms[0].elements[0].value = email;

    If you have more than one variable in the query string, use a more general method
    Like this: Request Object for Javascript

  3. #3
    SitePoint Guru moonman's Avatar
    Join Date
    Dec 2000
    Location
    The Sea of Tranquility
    Posts
    696
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers Jofa, it's working like a dream.

    I have a new problem now though. I need to get the form submitting to the email address that has populated the text box.


    Things are never simple

  4. #4
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    document.forms[0].action = 'mailto:' + email;

    Or, even better:
    document.forms[0].action = 'mailto:' + email + '?subject=Some descriptive title';

    NB! The form's other attributes must be...
    <form method="post" enctype="text/plain">

    Things are often more simple than you think

  5. #5
    SitePoint Guru moonman's Avatar
    Join Date
    Dec 2000
    Location
    The Sea of Tranquility
    Posts
    696
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep, that worked fine.

    The only problem is that I get a pop-up box saying "This form is being submitted using e-mail." Blah Blah Blah. Then is it says "A program is trying to automatically send email on your behalf." and it warns about a virus. Is there any way round this???

  6. #6
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Changing security settings in Outlook, but I wouldn't recommend that
    Anyway, if you change your security settings, that doesn't change what all other users will see


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
  •