How do you set a default value for a 'textarea'?

Posted on 2010-01-06
Last Modified: 2013-12-12
I've got a form with a ' textarea' as I am trying to capture textual input of an undefined length (a blogg would be an example of this - the field is defined as 'text' on the mysql database) but it does not seem to be possible to set this with a default value. How can I set this area with the information such as it is that has already been captured and committed to the database (I want it to be open and available to be updated)?
Question by:me_patrick
    LVL 40

    Accepted Solution

    like this
    <TEXTAREA NAME="comments" COLS=40 ROWS=6>
    John said
    : I think it's a great idea
    : but it needs more thought

    Just put the value between the starting and closing tag
    LVL 11

    Assisted Solution



    <textarea rows="2" cols="20">
    Your Default Information.

    if you have the information  already captured in a variable named "$Text" :

    <textarea rows="2" cols="20">
    <?php echo($text); ?>
    LVL 5

    Assisted Solution


    If you are using ASP, then try the below code.

    TextAreaValue = "DefaultValue"

    <textarea name="txtTextArea"><%=TextAreaValue%></textarea>

    And you can use Request.Form("txtTextArea") to get the text area value when you submit the form.

    Try It!
    LVL 107

    Assisted Solution

    by:Ray Paseur
    If you are sending out data that was received from outside your control, you have a  very important security issue here.  Do not just "echo" the data from your DB entry.  Instead you want to do something like this to avoid contaminating your clients with malicious code:

    echo "<textarea>";
    echo htmlentities($text_from_database);
    echo "</textarea>\n";

    Always... Filter Input / Escape Output!

    Best regards, ~Ray
    LVL 11

    Expert Comment

    "I set this area with the information such as it is that has already been captured and committed to the database"

    "Do not just "echo" the data from your DB..."

    If you have to filter data that is already in your DB, I think that the security issue will be in another part of your system.... =P

    Author Closing Comment

    Yes of course - sorry, I've been an absolute nit-wit .... trying to think about too much at the same time.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Showing your events from Google Calendar in Google Maps Why? I travel all week and I thought it would be ideal if staff in office knew where I was based on my calendar. (OK real reason: my son wanted to see where I would be working, and I thoug…
    Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
    In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
    The viewer will learn how to count occurrences of each item in an array.

    734 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

    23 Experts available now in Live!

    Get 1:1 Help Now