Skip to content Skip to sidebar Skip to footer

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:

<divclass="contact-form"><br><divclass="alert alert-success hidden"id="contactSuccess"><strong>Success!</strong> Your message has been sent to us.
 </div><divclass="alert alert-error hidden"id="contactError"><strong>Error!</strong> There was an error sending your message.
 </div><formname="sentMessage"id="contactForm"novalidate><divclass="form-group"><inputtype="text"class="form-control"placeholder="Full Name"id="RecipientName"requiredname="RecipientName"data-validation-required-message="Please enter your name" /></div><divclass="form-group"><inputtype="email"class="form-control"placeholder="Email"id="RecipientEmail"name="RecipientEmail"requireddata-validation-required-message="Please enter your email" /></div><divclass="form-group"><textarearows="10"cols="100"class="form-control"placeholder="Please enter your message"id="RecipientMessage"name="RecipientMessage"requireddata-validation-required-message="Please enter your message"minlength="5"data-validation-minlength-message="Min 5 characters"maxlength="999"style="resize:none"></textarea></div><inputclass="btn btn-primary pull-right"type="submit"id="EmailSendButton"name="EmailSendButton"value="send message"onclick="EmailData()"></form><br /><br /><divid="EmailConfirmation"></div></div><script>functionEmailData() {
    $("#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"