I have a problem saving the textarea value and format. The values and the format is not the same when I save it.
Below is my sample coding:
<script>
function save()
{
TestVar = document.getElementById("text2").value;
mydoc = document.open();
mydoc.write(TestVar);
}
</script>
</head>
<body>
<form id=formtest>
<textarea name="textarea" id="text2"></textarea>
<input type="button" value="save" onclick="save()">
</form>
</body>
For example, if I am typing the words in the textarea are:
Once there lived a greedy man in a small town.
He was very rich, and he loved gold and all things fancy.
Then, when I've clicked the Save button, the result is shown, it cannot follow my input new line format in the textarea:
Once there lived a greedy man in a small town. He was very rich, and he loved gold and all things fancy.
Actually, I want the expected result like the below picture:
Once there lived a greedy man in a small town.
He was very rich, and he loved gold and all things fancy.
Hope someone can guide me on how to solve the problem. Thanks.