Current location: Hot Scripts Forums » General Web Coding » HTML/XHTML/XML » simple text area help


simple text area help

Reply
  #1 (permalink)  
Old 03-09-10, 04:23 AM
ben_johnson1991 ben_johnson1991 is offline
Newbie Coder
 
Join Date: Dec 2009
Posts: 11
Thanks: 4
Thanked 0 Times in 0 Posts
Exclamation simple text area help

Hey.
I was just wondering how to keep the contents of a textbox the same when it is submited, displayed an edited.

Basically, if the followed is entered

"please help
I don't know what i'm doing"

If would come as
"please help I don't know what i'm doing"

How can I keep the wrapping?

I've seen a few forums, but they arent clear

could you should be where certain functions need to go, and if it will work with displaying and future editing?

Cheers!
Reply With Quote
  #2 (permalink)  
Old 03-09-10, 02:45 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
I'm not sure what you're requesting, since if the textarea isn't wide enough for the whole string on entry, it wraps, without an CR/LF, but later displays 'unwrapped' when it has a wider area.

Assuming you want to force wrapping, based on the width of the textarea, you could use: PHP: wordwrap - Manual

If the <textarea> tag has 35 columns, you could set the wordwrap to be 35.
Reply With Quote
  #3 (permalink)  
Old 03-10-10, 12:28 AM
ben_johnson1991 ben_johnson1991 is offline
Newbie Coder
 
Join Date: Dec 2009
Posts: 11
Thanks: 4
Thanked 0 Times in 0 Posts
Hey.

I simple have
<textarea name="" cols="10" rows="5">Words go Here</textarea>

And obviously when the user types, presses enter, and a this produces a new line.

but once submited to the database or printed, all line breaks do not appear.. it just comes all as one long paragraph..

and I was wondering how to keep the layout of the text as the user intended to stay the same.


Similar to this site, where I write in the reply box, all of which im typing are keeping their layout, including all of the line breaks.

Does that make sense?

Cheers!
Reply With Quote
  #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
Reply

Bookmarks

Tags
easy, html, textarea, wrapping


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
text box with scroll bar silvermane CSS 7 01-16-09 03:03 AM
div css theighost CSS 11 09-14-08 02:30 AM
Draggable Tables Ares JavaScript 10 08-03-06 06:55 AM
Need Your HelP! Loading Multiple External Text into Multiple Dynamic Text Fields Flash_Boi Flash & ActionScript 2 03-30-06 03:27 PM
picking random entries with a filter... Double selection problem dsumpter PHP 7 11-16-03 07:19 PM


All times are GMT -5. The time now is 09:12 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.