Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy 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
    Regular Coder
    Join Date
    May 2002
    Location
    Helsinki, Finland
    Posts
    231
    Thanks
    0
    Thanked 1 Time in 1 Post

    Thumbs up

    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

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Posts
    626
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    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.

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,966
    Thanks
    0
    Thanked 236 Times in 233 Posts
    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.

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    41 8' 52" N -95 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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. ;)

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Location
    The Planet Earth Code Poet: True
    Posts
    282
    Thanks
    0
    Thanked 1 Time in 1 Post
    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.

  • #8
    Senior Coder
    Join Date
    Jun 2002
    Location
    41 8' 52" N -95 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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. ;)

  • #9
    Senior Coder
    Join Date
    Jun 2002
    Location
    41 8' 52" N -95 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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. ;)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •