Sign in to follow this  
boolean

[web] Line breaks in forms

Recommended Posts

boolean    1829
Just a quick question. I am wondering how websites detect when the user has pressed enter when typing into a form, and knows they have moved onto a new line. At the moment the user has to type < br> into the form, but I would rather the website detect it and insert the < br> tag itself. Any ideas? [Edited by - boolean on November 29, 2005 2:25:10 AM]

Share this post


Link to post
Share on other sites
ToohrVyk    1595
I'm not sure I understand. Are you using a <textarea> (in which case I don't know what tag you are talking about) or a vertical sequence of <input type=text>, where the next should appear when the last one is written to (in which case what you might want to add an onKeyPress event).

Share this post


Link to post
Share on other sites
boolean    1829
yep, in <textarea>

What I mean is while the user is typing in text into the textarea, if they want to send the following line of text:

Example 1 :

Hello
My name is bob

No really, it is

then they have to type:

Example 2 :
Hello< br>My name is bob< br>No really, it is

What I am trying to figure out is how forms like the ones used on GDnet figure out that I put hit enter in Example 1 to move to a new line, and send the < br> tags back to the database, and do not require the user to format their text with < br> tags like the second example

Share this post


Link to post
Share on other sites
ToohrVyk    1595
PHP has the nl2br function which automatically replaces newlines with
tags. Other server-side script languages would naturally have either an equivalent, or a strreplace function which you can use to replace "\n" by "<br>".

Example:


$post = $_REQUEST["text"];
$database->store( nl2br($post) );


Share this post


Link to post
Share on other sites
boolean    1829
ah groovy, that should give me something to go off for a while.

The hardest part of it was I had no idea what to even start searching google with, so this helps [smile]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this