Reputation: 3325
I'm trying to print newline into textarea.
I have this string:
$coords = $row->lat.','.$row->lon."\r\n"
When I use the following javascript command:
alert(coords);
I get:
-35.308401,149.124298
-35.307841,149.124298
However, when I view it in a textarea, I get:
-35.308401,149.124298 -35.307841,149.124298
How do I make the newlines display in the textarea?
More Information:
alert window display:
textarea:
Code:
<textarea name="addrs" rows=5 cols=80>-35.308401,149.124298 -35.307841,149.124298</textarea>
Further Information: This is how form is created and text written to textarea
function openMapWindow (data) {
alert(data);
var mapForm = document.createElement("form");
mapForm.target = "Map";
mapForm.method = "POST"; // or "post" if appropriate
mapForm.action = "http://www.xxx.com/map.php";
var mapInput = document.createElement("input");
mapInput.type = "text";
mapInput.name = "addrs";
mapInput.value = data;
mapForm.appendChild(mapInput);
document.body.appendChild(mapForm);
map = window.open("", "Map", "status=0,title=0,height=600,width=800,scrollbars=1");
if (map) {
mapForm.submit();
} else {
alert('You must allow popups for this map to work.');
}
}
function mapSuppliers(customer_id) {
$.get("get.map.points.php", { c_id: customer_id },
function(data){
if (data!='') {
openMapWindow(data);
} else {
alert("Missing map coordinates - cannot display map (data: " + data + ")");
}
});
}
Upvotes: 0
Views: 874
Reputation: 26
I know this question is quite old already, but I will post my answer just in case anyone comes here.
For example, if we would like to show this text in textarea:
hi Masume
have a nice day!
With PHP:
echo "hi Masume".chr(13)."have a nice day!";
With JS:
textareaElement = 'hi Masume' + String.fromCharCode(13) + 'have a nice day!';
Upvotes: 1
Reputation: 10350
You are trying to have multiple rows in an input field.
Consider updating your code to:
var mapTextarea = document.createElement("textarea");
mapTextarea.name = "addrs";
mapTextarea.value = data;
mapForm.appendChild(mapTextarea);
Upvotes: 3