Reputation: 3917
I know how to submit a form. I know how to use a mailto: link. What I can't figure out is how to do both when the user clicks a single link (or button).
Is there a way to both submit form data and open the email client? Was thinking some variation of a mailto: link with an onclick JavaScript attached; but I can't figure out how to submit form data without clicking a Submit button. (Or the flipside -- opening the user's email client with JavaScript attached to the Submit click?)
Upvotes: 0
Views: 291
Reputation: 503
If what you want is to first open the email client, and then send automatically the email through the email client, that is not possible.
Otherwise, Niraj's answer suits well, but it will:
Upvotes: 0
Reputation: 15457
The easiest way to achieve this is to use a combination of JavaScript / jQuery and HTML. Create a link using a
and add the onclick
parameter to it, which can trigger the form submission:
Using jQuery:
<a href="mailto:[email protected]" onclick="$('#myform').submit();">Submit</a>
Using JavaScript:
<a href="mailto:[email protected]" onclick="document.getElementById('myform').submit();">Submit</a>
Upvotes: 1