[web] Line breaks in forms

This topic is 4619 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

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 on other sites
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 on other sites
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 on other sites
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 on other sites
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]

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 14
• 30
• 13
• 11
• 11
• Forum Statistics

• Total Topics
631782
• Total Posts
3002325
×