View Single Post
  #4 (permalink)  
Old 03-10-10, 02:39 AM
dayworker dayworker is offline
Newbie Coder
 
Join Date: Feb 2010
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Never found an easy way

I don't think there's any easy way to do this. The textarea doesn't have a line feed where it wraps at the col width, only where the user inserts it by hitting return. Maybe strText.replace("\n", "<br><br>") can help with a database field.
I've found client side formatting with JavaScript is labor intensive. Generally it seems easier to add the formatting server side using the Perl Text::Wrap module. I don't know what PHP can do.
For a little quick formatting I notice the 'pre' html tag holds on to the paragraph indents.


<script type="text/javascript">
function showText()
{
var theText = document.getElementById('tatext').value;
var strText = theText.replace("\n", "<br /><br />");
var newText = "<pre>" + strText + "</pre>";
document.getElementById('TAT').innerHTML = newText;
}
</script>

<textarea id = "tatext" rows = "10" cols = "40" wrap = "hard"></textarea>
<br />
<input type = "button" value = "UP" onclick = "showText()">
<hr>
<div id = "TAT">&nbsp;</div>
Reply With Quote