Web Analytics Made Easy -
StatCounter disable the text in the textarea - CodingForum

Announcement

Collapse
No announcement yet.

disable the text in the textarea

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • disable the text in the textarea

    i have a textarea where terms of agreement is placed. I want the text inside it to be disable if a user tries to change it. Can you help me?Tnx

  • #2
    either
    <textarea ... readonly="readonly"></textarea>
    and/or :
    <textarea ... disabled="true"></textarea>

    I prefer readonly -attribute, which just prevents modifying. Disabled attribute makes the whole area look disabled (grey) and disabled textarea's data isn't submitted, when a form is posted.
    Zvona
    First Aid for
    Web Design

    Comment


    • #3
      You might want to use the onFocus event to remove focus so that is also works in NS4.

      onFocus="this.blur()"

      This will work in both IE and NS whereas the readonly property only works with IE and I believe NS6.

      Comment


      • #4
        Actually, last I heard there was a known bug in which onfocus="this.blur()" does NOT work for Gecko browsers (NS6 included). It may have been fixed for Mozilla 1.0 though, and is worth further testing if I get around to it.

        Use a combination of:

        <textarea readonly="readonly" onfocus="this.blur()">

        For best results.
        jasonkarldavis.com

        Comment


        • #5
          but you can still right-click inside the textarea and it will not trigger onfocus event, so the user can do right-click & paste.
          so you must use this combination:

          <textarea readonly="readonly" onfocus="this.blur()" onchange="this.value='blah blah'">blah blah</textarea>

          to ensure best results


          Originally posted by jkd
          Actually, last I heard there was a known bug in which onfocus="this.blur()" does NOT work for Gecko browsers (NS6 included). It may have been fixed for Mozilla 1.0 though, and is worth further testing if I get around to it.

          Use a combination of:

          <textarea readonly="readonly" onfocus="this.blur()">

          For best results.
          Glenn
          vBulletin Mods That Rock!

          Comment


          • #6
            Can't you also do

            onchange="this.value=this.default.value"

            ?
            Former ASP Forum Moderator - I'm back!

            If you can teach yourself how to learn, you can learn anything. ;)

            Comment


            • #7
              Originally posted by whammy
              Can't you also do

              onchange="this.value=this.default.value"

              ?
              Did you try it? It throws up errors when I try it.

              Comment


              • #8
                Hmm... you're right. I hadn't tried it... I could *swear* I read about that somewhere - must have dreamed it, LOL
                Former ASP Forum Moderator - I'm back!

                If you can teach yourself how to learn, you can learn anything. ;)

                Comment


                • #9
                  OK, I didn't dream it!

                  I just had the wrong syntax:

                  <form>
                  <textarea name="blah" rows=8" cols="50" onchange="this.value=this.defaultValue">asdf</textarea>
                  </form>

                  works!

                  Former ASP Forum Moderator - I'm back!

                  If you can teach yourself how to learn, you can learn anything. ;)

                  Comment

                  Working...
                  X