How to insert line break into a TextArea control

Posted on 2007-10-20
Last Modified: 2012-06-22
Greetings everyone,

This is probably a cheap one, for that I apologize.

I will like to insert a br into a textArea so that when I hit then return key, the next text begins on a new line.
For instance, if I  have the following text:  Hello, World!
I am Christopher Columbus and I discovered America.

I would like "I am Christopher Columbus and I discovered America to start on a new line.

So far, everying is wrapping naturally which is fine but I want to be able to begin a new paragraph on a new line.

Can someone please help?

Comments: <textarea cols="20" rows="8" name="comments" maxlength="200" WRAP="Virtual"> </textarea>

thanks much in advance
Question by:nigerman
    LVL 8

    Expert Comment


    just set the multiline property of the textarea.

    fyi; no html elements are used in a text area, when you hit enter a line break character is inserted, instead of a <br>

    good luck
    LVL 8

    Expert Comment

    oh, a text area is always multiline.. so it should already go to the next line when you hit <enter>

    just see the comment textarea on this question page source in experts exchange,

            <textarea id="text" name="text" rows="15" cols="60" class="rightEdge"></textarea>

    perhaps you have something on your form interfaring with your <enter> key?

    Author Comment

    Well this occurs on details page - the page the displays info you enter on the textArea.

    Here is that code and who knows what could be interferring with it.

    <table width=100% cellspacing=10 valign=top ID="Table2">
                 <P align=left><STRONG><FONT face=Arial></FONT></STRONG>&nbsp;</P>
                                  '... create and open connection ...
                                Set conn = Server.CreateObject("ADODB.Connection")
                                 conn.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
                                "DATA SOURCE=" & server.mappath("Database/SThom.mdb")
                                id = request("newsID")
                                Set RS = conn.Execute("SELECT details FROM tblAnnouncements WHERE newsID=" & id )
                                   Response.Write RS(0)

    LVL 8

    Expert Comment

    Ah it's the generation phase of the page. I thought you were refering to runtime when you said 'hit enter'.

    So, the code you sent is correct, you don't need to replace -new line- characters with <br> tags when generating a <textarea>, since it already uses -new line-s.  So it looks like the problem is with the recorded values, have you checked the data to see if it has -new line- characters?
    LVL 8

    Accepted Solution

    if the data doesn't contain new lines, it's probably related to your data retrieval page, so you'll have to modify your code on data retrieval to store the data without replacing / removing -line break- characters, and everything will work fine.

    good luck

    Author Comment

    thank you very much MrRobot.

    Sorry for late response.

    my kids (2 boys) are in first and second grades and today is their school's fall cleanup day. I had to rush to assist with cleaning up the property, hence the late response.
    LVL 8

    Expert Comment

    you're welcome nigerman =))

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
    This demonstration started out as a follow up to some recently posted questions on the subject of logging in: and…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now