Forum Moderators: open
<body>
<div id="mine"></div><br>
<form name=form>
<textarea cols=300 rows=15 name=text onKeyUp="document.all.mine.innerHTML=document.form.text.value"></textarea>
</form>
how do you add the <br> to the div?
as in if i type
h
e
l
l
o
it shows up as
h e l l o
how can i add the <br> or equivalent
He says that if he types in
a
b
c
he gets a b c. That's due to the way a browser interprets HTML.
I suggested typing: a<br>b<br>c. HelenDev's is much better, but I'd amend it to:
document.form.text.value.replace(/\r\n¦\n/g,"<br />")
because I think non-windows OS's use \n for line-breaks.
(actually, "\n" might do the trick equally well all round)
[Replace the broken pipe ¦ as usual]
<html><head>
<title>WriteDiv</title>
<style>#targdiv{font-family:monospace;}</style>
<script>
function fillTarg()
{
var TARG = document.getElementById("targdiv")
var AREA = document.getElementById("area")
TARG.innerHTML = AREA.value.replace(/\r\n[red][b]¦[/b][/red]\n/g,"<br>").replace(/\s/g," ")
}
</script></head><body><textarea id="area" rows=8 cols=30 onKeyUp="fillTarg()"></textarea>
<div id="targdiv"></div>
</body></html>