Reputation:
So on my website you are able to send messages. I use the nl2br() function so if someone presses enter, their text will have linebreaks. I realized though, if the person typing the text doesn't press enter and is instead wrapped by the textarea, the text is still broken. How can I avoid this? (How can I avoid linebreaks if the user doesn't press enter)
Upvotes: 0
Views: 674
Reputation:
I found the answer:
I had wrap="hard" so when I changed it to wrap="soft" the user had to press enter to add linebreaks. Thanks for everyone's help.
Upvotes: 2
Reputation: 21918
Set up your textarea like this:
<textarea style="white-space: nowrap; overflow: auto;">
</textarea>
Browser will no longer display automatic wraps, and will add scrollbars when user types past the right edge.
Upvotes: 2
Reputation: 8884
The linebreaks caused by wrapping in the textarea are only displayed in the browser and will not be submitted with the form. If you don't want them to be converted to <br />
, that's fine, because they won't. (Not sure I understand your question.)
Upvotes: 1
Reputation: 10489
You can use the CSS style overflow: auto
on the textarea so that the textarea will render with a scrollbar if the text exceeds the width of the textarea.
#textareaId {
overflow: auto;
}
Upvotes: 3