Reputation: 2468
I have this little problem. I have this javascript in my html page:
function myfunction(form)
{
var name = document.details.txtName.value + "\n";
var street = document.details.txtStreet.value + "\n";
var city = document.details.txtCity.value + "\n";
var stateProvince = document.details.txtStateProvince.value + "\n";
var postalCode = document.details.txtPostalCode.value + "\n";
var country = document.details.txtCountry.value + "\n";
var homeTel = document.details.txtHomeTel.value + "\n";
var workTel = document.details.txtWorkTel.value + "\n";
var fax = document.details.txtFax.value + "\n";
var mobile = document.details.txtMobile.value + "\n";
var email = document.details.txtEmail.value + "\n";
var enquiry = document.details.txtEnquiry.value + "\n";
var message = (name +
street +
city +
stateProvince +
postalCode +
country +
homeTel +
workTel +
fax +
mobile +
email +
enquiry);
alert(message);
location='mailto:[email protected]?subject=Message From Redec Website&body=' + message;
return false; //So that the page can stay at its current location.
In the messagebox that pops up, it displays the strings underneath each other, which I want.
but when this opens outlook it is all in one long string. how can I fix this? }
Upvotes: 0
Views: 517
Reputation: 6873
The mailto is particular attribute. You have to encode the string using escape
function.
But for the new lines, you can use %0D%0A.
See this site for more informations.
Upvotes: 2
Reputation: 96810
You're inserting the text as HTML, so new line characters '\n'
are simply parsed as 'n'
. To insert a line break, using the corresponding HTML element <br>
.
For example:
var name = document.details.txtName.value + "<br>";
// ^^^^
Upvotes: 1