Populate Form Field
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.
Put the email address in the link's query string, like this
<a href="email@example.com">Send an email to firstname.lastname@example.org</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.elements.value = email;
If you have more than one variable in the query string, use a more general method
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
document.forms.action = 'mailto:' + email;
Or, even better:
document.forms.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 :)
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???
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