0

I am passing data from a textarea to a div with javascript. The problem is the div is ignoring line breaks.

document.getElementById('layer1').innerHTML =  document.getElementById('reply').value.replace("\n", "<br /><br />");

e.g... i entered this in the textarea

test1


test5


test6


the result was in the div

test1

test5 test6


the div is completely ignoring the line breaks. any idea why?

2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by fxm
0

line breaks.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta name="generator" content=
    "HTML Tidy for Windows (vers 25 March 2009), see www.w3.org">
    <title></title>
  </head>
  <body>
	<textarea onclick="tfr()" id='ta'></textarea>
	<div id='dv'></div>

	<script type="text/javascript">
		function tfr() {
		    document.getElementById('dv').innerHTML = document.getElementById('ta').value.replace(/\n/g, "<br /><br />")
		}
	</script>
  </body>
</html>
0

i tried that code and it doesn't work. it still appears as

test1

test5 test6


rather than

test1


test5


test6

0

Tested here in Chrome, Firefox, Safari(pc), Opera, and IE8.

They all give the correct result.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.