Results 1 to 3 of 3

Thread: Setting Element to Readonly

  1. #1
    Join Date
    Feb 2005
    Posts
    54
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Setting Element to Readonly

    Howdy all,

    If I have a textbox, such as:
    Code:
    <textarea name="mytext" id="mytext" rows="2" columns="50">
    I know I can add a readonly attribute to it to lock it down, such as:
    Code:
    <textarea READONLY name="mytext" id="mytext" rows="2" columns="50">
    Question is this: via JavaScript, can I set this textarea as READONLY?

    What I'm trying to accomplish here is that after a user enters their text into the <textarea>, when they click a certain button, I'd like to lock down the textarea as READONLY via a JavaSript thereby locking their comments.

    This obviously doesn't work:
    Code:
    function lockit()
    {
       document.getElementByID('mytext') = READONLY;
    }
    I know I'm missing something here (see red):
    Code:
    function lockit()
    {
       document.getElementByID('mytext')._____ = READONLY;
    }
    ...but can't figure out what and haven't been able to successfully Google search either...

    Any help would be greatly appreciated...

    Thanks,

    - I

  2. #2
    Join Date
    Feb 2005
    Posts
    54
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default


    BOINK...

    scratch that... this will do:

    Code:
    function lockit()
    {
       document.getElementByID('mytext').disabled = true;
    }
    Sorry for the brain fart.

    - I

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    .readonly = true should work too, and better (no greying-out of the element).
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

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