Click to See Complete Forum and Search --> : insert line break
piertiong
12-01-2003, 09:58 PM
hi everyone,
i would like to enquiry about how do i go about inserting line breaks "<br />" into a text field when my user presses the "enter" key?
thanks alot.
lillu
12-02-2003, 03:24 AM
Hi,
It depends where or how you wish to store those line breaks.
Do you want to preserve them in the output as well eg. when pulling some texts from a database and display it on the page?
What I don't understand it the "<br />". In fact, you cannot insert another html tag within a textarea tag, nor any other new line constants eg. vbcrlf. The contol itself has to offer some facility for line breaks or you can do the formatting on the fly later.
If you're only concerned with the input, then use this:
<textarea name="textarea1" rows="5" cols="40" wrap="physical">
It works in traditional ASP and the line breaks will be preserved in the database too.
However outputting the results mighth require something else.
piertiong
12-02-2003, 03:58 AM
what i meant was, i want the code "<br />" to appear in the text field when the user presses the enter key.
just like when the user types in <br /> manually himself.
and the code <br /> will be stored into the database as a string.
lillu
12-02-2003, 08:41 AM
Well, it's still not what you may want but I used this to replace
the enter to convert a linebreak in a form textfield into a <br /> tag.
The database stores it as Chr(13) or Chr(10) and Chr(13) depending on the system all the input coming from the textfield and if you set it wrap="physical". As I pointed out, it does not store it as "<br />" because it comes from inside an HTML tag.
What I do here is to replace all instances of the constanst with "<br />" when doing the html output with the Response.Write
Replace(Chr(13), "<br />")
Replace(Chr(13) & Chr(10), "<br />")
So the entries made will be formatted as originally. Sorry if it's not the solution you're looking for.
piertiong
12-03-2003, 08:01 AM
Originally posted by lillu
Well, it's still not what you may want but I used this to replace
the enter to convert a linebreak in a form textfield into a <br /> tag.
The database stores it as Chr(13) or Chr(10) and Chr(13) depending on the system all the input coming from the textfield and if you set it wrap="physical". As I pointed out, it does not store it as "<br />" because it comes from inside an HTML tag.
What I do here is to replace all instances of the constanst with "<br />" when doing the html output with the Response.Write
Replace(Chr(13), "<br />")
Replace(Chr(13) & Chr(10), "<br />")
So the entries made will be formatted as originally. Sorry if it's not the solution you're looking for.
your solution sounds great, so <br /> stands for Chr(13) OR Chr(10) and Chr(13)?
lillu
12-03-2003, 08:13 AM
Chr(13) - this means carriage return <br />
Chr(10) & Chr(13) - this is carriage return and line feed
<br /><br /> (might well be a <p>, the only problem that <p> is not well-formed so it's better to use 2 <br />-s for a break and a new line.