Forum Moderators: open
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>LiveUpdate with JS</title>
<script Language="javascript">
function LiveUpdate(source,dest)
{
dest.innerHTML = source.value.replace("\n","<br>");
}
</script>
</head>
<body> <textarea rows="5" cols="50" id="myTextBox" onchange="LiveUpdate(this;document.getElementById('LiveDisplay'))"></textarea>
<p id="LiveDisplay"></p>
</body>
</html>
1. The arguments are separated by a semicolon ';' in the function call. Should be a comma.
2. For the update to be really 'live', you need to use the onKeyUp event handler. onchange only fires when the textarea loses focus.
So..
onKeyUp="LiveUpdate(this,document.getElementById('LiveDisplay'))" 3. To replace all instances of \n in the value string you need to use a regular expression with the 'g' modifier (global) as first arg.
dest.innerHTML = source.value.replace(/\n/g,"<br>"); That should now work.