Text To Outlook Body
I have this button which when clicked opens outlook with the details i have provided. I also have a TEXTAREA which is holding certain texts. I'm looking for a way to have this text
Solution 1:
Try changing this line:
var emailBody = 'Body';
To:
var emailBody = $('#holdtext').val();
Because textarea
is a form element.. val()
is the proper way to retrieve the text inside of it.
Let me know if this helps!
UPDATE
To preserve the line breaks.. change this line:
window.location = 'mailto:' + email + '?subject=' + subject + '&body=' + emailBody;
To:
window.location = 'mailto:' + email + '?subject=' + subject + '&body=' + encodeURIComponent(emailBody);
Solution 2:
Here is an example that I have used with the textarea tag and javascript:
<div class="contact-form">
<br>
<div class="alert alert-success hidden" id="contactSuccess">
<strong>Success!</strong> Your message has been sent to us.
</div>
<div class="alert alert-error hidden" id="contactError">
<strong>Error!</strong> There was an error sending your message.
</div>
<form name="sentMessage" id="contactForm" novalidate>
<div class="form-group">
<input type="text" class="form-control" placeholder="Full Name" id="RecipientName"
required name="RecipientName"
data-validation-required-message="Please enter your name" />
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Email"
id="RecipientEmail" name="RecipientEmail" required
data-validation-required-message="Please enter your email" />
</div>
<div class="form-group">
<textarea rows="10" cols="100" class="form-control"
placeholder="Please enter your message" id="RecipientMessage" name="RecipientMessage"
required data-validation-required-message="Please enter your message" minlength="5"
data-validation-minlength-message="Min 5 characters" maxlength="999"
style="resize:none">
</textarea>
</div>
<input class="btn btn-primary pull-right" type="submit" id="EmailSendButton"
name="EmailSendButton" value="send message" onclick="EmailData()">
</form><br /><br />
<div id="EmailConfirmation"></div>
</div>
<script>
function EmailData() {
$("#EmailSendButton").attr("disabled", "true");
var url = "/Home/EmailData";
var recipientName = $("#RecipientName").val();
var recipientEmail = $("#RecipientEmail").val();
var recipientMessage = $("#RecipientMessage").val();
var postData = { 'Name': recipientName, 'Email': recipientEmail, 'Message': recipientMessage }
$.post(url, postData, function (result) {
$("#EmailConfirmation").css({ 'display': 'block' });
$("#EmailConfirmation").text(result);
$("#EmailConfirmation").attr({ class: 'alert alert-success' })
$("#RecipientName").val('Your Name *');
$("#RecipientEmail").val('Your E-mail *');
$("#RecipientMessage").val('Your Message *');
})
}</script>
Post a Comment for "Text To Outlook Body"