readOnly attribute doesn't work for drop down list?

Discussion in 'Javascript' started by Matt, Jun 28, 2004.

  1. Matt

    Matt Guest

    I want to know if readOnly attribute doesn't work for drop down list?
    If I try disabled attribute, it works fine for drop down list. When I
    try text box, it works fine for both disabled and readOnly attribute.

    For example, #1 will work, but #2 doesn't work

    1) <SELECT name="streetDirection" class="FormInput" DISABLED>
    In JavaScript, I have InputForm.streetDirection.disabled = false;

    2) <SELECT name="streetDirection" class="FormInput" readOnly>
    In JavaScript, I have InputForm.streetDirection.readOnly= false;

    any ideas? thanks!!
     
    Matt, Jun 28, 2004
    #1
    1. Advertising

  2. Matt

    Mick White Guest

    Matt wrote:

    > I want to know if readOnly attribute doesn't work for drop down list?
    > If I try disabled attribute, it works fine for drop down list. When I
    > try text box, it works fine for both disabled and readOnly attribute.
    >
    > For example, #1 will work, but #2 doesn't work
    >
    > 1) <SELECT name="streetDirection" class="FormInput" DISABLED>
    > In JavaScript, I have InputForm.streetDirection.disabled = false;
    >
    > 2) <SELECT name="streetDirection" class="FormInput" readOnly>
    > In JavaScript, I have InputForm.streetDirection.readOnly= false;
    >
    > any ideas? thanks!!

    "Select" is always read only.
    Mick
     
    Mick White, Jun 28, 2004
    #2
    1. Advertising

  3. Matt wrote:

    > I want to know if readOnly attribute doesn't work for drop down list?



    > 2) <SELECT name="streetDirection" class="FormInput" readOnly>
    > In JavaScript, I have InputForm.streetDirection.readOnly= false;


    According to
    http://www.w3.org/TR/html4/interact/forms.html#h-17.6
    there is no readonly attribute defined for <select> elements thus there
    can't be a property for HTMLSelectElement objects:
    http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-94282980

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jun 28, 2004
    #3
  4. Matt

    Grant Wagner Guest

    Matt wrote:

    > I want to know if readOnly attribute doesn't work for drop down list?
    > If I try disabled attribute, it works fine for drop down list. When I
    > try text box, it works fine for both disabled and readOnly attribute.
    >
    > For example, #1 will work, but #2 doesn't work
    >
    > 1) <SELECT name="streetDirection" class="FormInput" DISABLED>
    > In JavaScript, I have InputForm.streetDirection.disabled = false;
    >
    > 2) <SELECT name="streetDirection" class="FormInput" readOnly>
    > In JavaScript, I have InputForm.streetDirection.readOnly= false;
    >
    > any ideas? thanks!!


    The readonly attribute appears to not be supported on <select> elements
    by Firefox 0.9, IE6SP1 or Opera 7.51.

    <url:
    http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/select.asp
    /> confirms this by not listing "readonly/readOnly" as a valid property
    on the <select> object.

    <url: http://www.w3.org/TR/html401/interact/forms.html#h-17.12.2 /> also
    seems to confirm this behavior: "The following elements support the
    readonly attribute: INPUT and TEXTAREA."

    That spec doesn't specifically exclude SELECT, but it doesn't include it
    either, and the fact that none of the 3 user agents I tested support
    readonly on <select> points to user agents adhering to the letter of the
    spec.

    In other words, what you are seeing is documented behavior.

    Besides, what would be the point of a readonly <select>? It would appear
    to be a normal <select>, but it wouldn't open as a normal <select> does,
    which would be very confusing for the user.

    --
    | Grant Wagner <>

    * Client-side Javascript and Netscape 4 DOM Reference available at:
    *
    http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

    * Internet Explorer DOM Reference available at:
    *
    http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp

    * Netscape 6/7 DOM Reference available at:
    * http://www.mozilla.org/docs/dom/domref/
    * Tips for upgrading JavaScript for Netscape 7 / Mozilla
    * http://www.mozilla.org/docs/web-developer/upgrade_2.html
     
    Grant Wagner, Jun 28, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SirPoonga
    Replies:
    2
    Views:
    821
    Ben Strackany
    Jan 7, 2005
  2. Matt
    Replies:
    2
    Views:
    19,155
  3. weiwei
    Replies:
    0
    Views:
    1,076
    weiwei
    Jan 5, 2007
  4. Jonathan Hyatt
    Replies:
    1
    Views:
    2,143
    Jonathan Hyatt
    Jun 8, 2004
  5. Replies:
    5
    Views:
    319
Loading...

Share This Page