Jump to content

How can i add a break space in a text area?


svgmx5

Recommended Posts

Does anyone know how you can a break or space every time a user presses the enter button while typing on a regular html form textarea?

 

I want it so every time a user is typing in a text area and they press enter a new space is added.

Link to comment
Share on other sites

This should be default behavior. If, you want it to show on an HTML page, you will need to use nl2br on the field when you display it (do not do it before you insert it into a database, better to keep it as the \n character). IE:

 

$text = isset($_POST['textareaname'])?$_POST['textareaname']:'';

echo nl2br($text); 

 

Should display the linebreaks properly.

 

EDIT:

Just saw that this was posted in the HTML section. Since it is HTML, I think you would need to use JavaScript to conver the \n (linebreak character) to <br />. Since I do not know Javascript I cannot offer much help then to set you on the right direction. If you are using PHP, the above advice will work.

 

EDIT:EDIT:

If you want to view it and do not care about formatting, encasing the value in a <pre></pre>  tags will display the line breaks properly as well.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.