I have a textarea where a user can insert some text, and after it hits the "Send" button, the text should be copied (as it was entered) in the default email window (I have tried with Outlook). For now, if I want to enter:
abcd
def
I will get the output:
abcd</br></br>def
This is the html file:
<div class="form-group">
<label for="message" class="sr-only">Message</label>
<textarea name="message" id="message" class="form-control" cols="30" rows="7" placeholder="Message" minlength="5" data-validation-minlength-message="Min 5 characters" maxlength="999" required></textarea>
</div>
<div class="form-group">
<input type="submit" value="Send Message" onclick="javascript: sendemail();" class="btn btn-primary" id="abcd">
</div>
And this is the .js file:
function sendemail() {
var name = document.getElementById('name').value;
var email = document.getElementById('email').value;
var message2 = document.getElementById('message').value;
var myLineBreak = message2.replace(/\r\n|\r|\n/g, "</br>");
var pattern = /[a-zA-Z0-9!#$%&'*+\/=?^_`{|}~.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*/;
if (name.length == 0)
alert("Please complete the Name field!");
else
if (pattern.test(String(email).toLowerCase()) == 0)
alert("Please enter a valid email address!");
else
if (message2.length < 5)
alert("Message too short!");
else {
document.getElementById("form1").action = "mailto:JustinF@somesite.com&body=" + myLineBreak;
document.getElementById("form1").submit();
}
}
I've tried also to add this to style.css:
#abcd {
white-space: pre-wrap;
}
but with no luck... ('abcd' is the id of the "Send" button)
tags?](https://stackoverflow.com/questions/784539/how-do-i-replace-all-line-breaks-in-a-string-with-br-tags) – Harshit Jan 07 '19 at 09:41