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 4 of 4
  1. #1
    New Coder
    Join Date
    Mar 2003
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    readonly attribute

    Hello people,

    I'm having a niggling difficulty using Internet Explorer, where the following code:
    x.setAttribute('readonly','true');
    does NOT set the readonly attribute to true.

    It's working fine in Mozilla, so I can't really see what the problem is (though I encountered something I'm guessing is pretty much the same in the x.className VS x.setAttribute('class','name') function problem.

    It's just a simple problem, but it's annoying the crap out of me.

    Please help!

    Much appreciated!
    - Vlaad

  • #2
    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
    Try using the DOM2 HTML extension:

    someElement.readOnly = true;

  • #3
    Regular Coder
    Join Date
    May 2002
    Location
    Helsinki, Finland
    Posts
    231
    Thanks
    0
    Thanked 1 Time in 1 Post
    Another way that should work:

    oElement.setAttribute("readonly","readonly");

    This is because attribute readonly can have only value "readonly". However, when dealing with booleans and controlling elements solely thru scripting, it's recommended to use the method jkd mentioned.
    Zvona
    First Aid for
    Web Design

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    My experience is that

    obj.setAttribute('foo','bar');

    often doesn't work in IE, for no reason, whereas

    obj.setAttribute('foo','');
    obj.foo = 'bar';

    is reliable.
    Last edited by brothercake; 06-06-2003 at 11:00 AM.
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark


  •  

    Posting Permissions

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