70535

On form submit, mailto from javascript with form values

I have a form, and when the form is submitted (input type="submit"), i would like to open the clients default mail-browser with a pre-populated email-message.

So when the user clicks submit two things need to happen. Open email and submit form.

Also, how can i use the values entered in the form to prepopulate the email?

I'm new to javascript-jquery so please, any code example would be of great help!

Thanks for your help!

Answer1:

Before submitting the form you could do:

window.location.href = 'mailto:nicola@mio.it';

this will open the predefined mail client and you can also prefill some field. look at the mailto sintax here or post some more info so that we can help you;

This could be done like this :

$('input[type=submit]').click(function(){ window.location.href = "mailto:" + $('#email').val(); });

Answer2:

you can prepopulate form with

$("textarea").val('Your message here! You\' have to strip \''); <hr>

if it's default email clien't, I'm afraid it's not possible

Answer3:

I have used a code like this when I needed to send via mailto using my local email client, it may help:

<div class="snippet" data-lang="js" data-hide="false"> <div class="snippet-code">

<html>
<head>
  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<form id="myform" enctype="text/plain" action="test.php" method="post" >
	<input type="text" value="value1" id ="field1" name="field1">
	<input type="checkbox" value="valuel2" id ="field2" name="field2" checked>
	<input type="checkbox" value="value3" id ="field3" name="field3" >
	<textarea id="myText" name ="texty">
	    Lorem ipsum...
	</textarea>
	<button onclick="sendMail(); return false">Send</button>
</form>
<script>
function sendMail() {
	$myform = $('#myform');
	$myform.prop ('action','mailto:mymail@mydomain.es');
	$myform.submit();
}
</script>

</body>
</html>


Recommend

  • Stuck on error loading scipy, using Homebrew install, on macOS Sierra
  • Graph database modelling: Should i use a collection node to avoid to many rel on a node
  • Tracking progress in python list(map(…))
  • How can I find shortened URLs that link to a specific long URL?
  • Rails actionmailer open host email app
  • Validate field and throw exception in JSF, but attach error message to another field?
  • SQL Server: INNER JOIN after UNION leads to slow Hash Match (Aggregate)
  • Fetching statements from Learning Locker LRS using TinCan API
  • Pathogen ignoring ftplugin scripts
  • nodeJS util.format passing an array
  • Positioning children objects in scene (car wheels hierarchy)
  • How to move again MainActivity after sending the mail?
  • SmtpClient sends email to junk
  • How to make nicEditor snaplet? (Several questions)
  • SQL - Select lowest values with group by and order by?
  • Cypher - matching two different possible paths and return both
  • Upload file that is in the cpan database
  • Clear fused location provider's location for testing
  • How do I display a dialog that asks the user multi-choice questıon using tkInter?
  • Clarification on min distance on LocationManager.requestLocationUpdates method, min Distance paramet
  • accepts_nested_attributes_for practical form use for in Rails 3
  • Intel-64 and ia32 atomic operations acquire-release semantics and GCC 5+
  • Zoom in and out of jPanel
  • Simulate click Geckofx vb,net
  • Spring Cloud Microservice Architecture Confusion
  • Firefox Extension - Monitor refresh and change of tab
  • Saving Changes After In-App Purchase Has Been Purchased
  • Transactional Create with Validation in ServiceStack Redis Client
  • How do I pass the string value parameter of the selected list item from an auto-populated dropdown l
  • Jquery UI tool tip close icon
  • Handling un-mapped Rest path
  • formatting the colorbar ticklabels with SymLogNorm normalization in matplotlib
  • PHP - How to update data to MySQL when click a radio button
  • HTML download movie download link
  • Incrementing object id automatically JS constructor (static method and variable)
  • To display the title for the current loaction in map in iphone
  • Acquiring multiple attributes from .xml file in c#
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • How can I remove ASP.NET Designer.cs files?
  • java string with new operator and a literal