disabled vs readonly input elements

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kaeli

    disabled vs readonly input elements


    Hi all,

    I have form elements that I want to not be editable. They should,
    however, be passed on submission. AFAIK, then, they need to be readonly.
    (intranet app where elments are created server-side according to perms
    of user with a jsp taglib, so users get some elements they can edit and
    some they can't, but all will be passed to next page)


    The problem with the readonly elements is, when I highlight the text, it
    highlights as though it is editable. When I then click backspace, as if
    to delete it, it goes back in the browser history (NN7 and IE6).
    I want the behavior to be that a user cannot even focus the element if
    it is readonly (like it would be if it were disabled). I also want
    readonly elements to be greyed out like they are when they are disabled.
    Can this be done without using style or javascript? (I can do both with
    style and JS, just wondering if there was a pure html way without using
    hidden fields.)

    TIA
    --
    --
    ~kaeli~
    In democracy your vote counts. In feudalism your count votes.



  • Mark Parnell

    #2
    Re: disabled vs readonly input elements

    On Tue, 6 Jan 2004 14:40:59 -0600, kaeli declared in
    comp.infosystem s.www.authoring.html:
    [color=blue]
    > I want the behavior to be that a user cannot even focus the element if
    > it is readonly (like it would be if it were disabled). I also want
    > readonly elements to be greyed out like they are when they are disabled.
    > Can this be done without using style or javascript? (I can do both with
    > style and JS, just wondering if there was a pure html way without using
    > hidden fields.)[/color]

    No. You can make it grey with CSS, but you can't stop the user from
    highlighting it. You could try and stop them from highlighting it using
    Javascript, but it won't work for everyone, and may annoy others. Does
    it actually need to be in an input field? Why not put it as normal text,
    and include it as a hidden field if you need it to be submitted?

    --
    Mark Parnell

    Comment

    • Anne van Kesteren

      #3
      Re: disabled vs readonly input elements

      Mark Parnell wrote:[color=blue]
      > No. You can make it grey with CSS, but you can't stop the user from
      > highlighting it. You could try and stop them from highlighting it using
      > Javascript, but it won't work for everyone, and may annoy others. Does
      > it actually need to be in an input field? Why not put it as normal text,
      > and include it as a hidden field if you need it to be submitted?[/color]

      ::selection and/or ::-moz-selection

      <http://www.w3.org/TR/2001/CR-css3-selectors-20011113/#UIfragments>
      <http://bugzilla.mozill a.org/show_bug.cgi?id =176170>


      --
      Anne van Kesteren
      <http://www.annevankest eren.nl/>

      Comment

      • kaeli

        #4
        Re: disabled vs readonly input elements

        In article <2iq9pqwk4vbv.1 faj2xdenfxig.dl g@40tude.net>,
        webmaster@clark ecomputers.com. au enlightened us with...[color=blue]
        >
        > No. You can make it grey with CSS, but you can't stop the user from
        > highlighting it. You could try and stop them from highlighting it using
        > Javascript, but it won't work for everyone, and may annoy others. Does
        > it actually need to be in an input field? Why not put it as normal text,
        > and include it as a hidden field if you need it to be submitted?
        >
        >[/color]

        Okay.

        Looks like it's javascript/CSS.
        This is an intranet app (with about 100 users) where everyone uses the
        same stuff (IE6/NN7), so no worries over it not working for some.
        Javascript and CSS are required. The site intentionally doesn't work if
        they are turned off. This is something I'd *never* do on an internet
        site, so don't yell at me. :)
        It used to be text if it wasn't editable, but people didn't like that
        look. They wanted a more consistent look and feel.

        --
        --
        ~kaeli~
        Going to church doesn't make you a Christian any more than
        standing in a garage makes you a car.



        Comment

        • Markus Ernst

          #5
          Re: disabled vs readonly input elements

          "kaeli" <tiny_one@NOSPA M.comcast.net> schrieb im Newsbeitrag
          news:MPG.1a65cf d5bc00a9d9989a7 4@nntp.lucent.c om...[color=blue]
          > In article <2iq9pqwk4vbv.1 faj2xdenfxig.dl g@40tude.net>,
          > webmaster@clark ecomputers.com. au enlightened us with...[color=green]
          > >
          > > No. You can make it grey with CSS, but you can't stop the user from
          > > highlighting it. You could try and stop them from highlighting it using
          > > Javascript, but it won't work for everyone, and may annoy others. Does
          > > it actually need to be in an input field? Why not put it as normal text,
          > > and include it as a hidden field if you need it to be submitted?
          > >
          > >[/color]
          >
          > Okay.
          >
          > Looks like it's javascript/CSS.
          > This is an intranet app (with about 100 users) where everyone uses the
          > same stuff (IE6/NN7), so no worries over it not working for some.
          > Javascript and CSS are required. The site intentionally doesn't work if
          > they are turned off. This is something I'd *never* do on an internet
          > site, so don't yell at me. :)
          > It used to be text if it wasn't editable, but people didn't like that
          > look. They wanted a more consistent look and feel.
          >[/color]

          I totally agree with you that from a usability point of view the actual spec
          regarding disabled and read only elements is a mistake. In many applications
          it is necessary to display form fields with values that cannot be changed,
          but have to be visible for consistence and must be submitted, too. I don't
          really see a reason for the behaviour which is actually described in the
          specs and realized in the browsers.
          - The read-only fields with the behaviour that you describe, but not greyed
          out or otherwise visibly marked are a kind of confusing the user.
          - The fact that disabled fields are not submitted is not satisfactory. There
          might be cases where the value is not needed, but then we could just not
          process it at the server side. For the other cases, where the value _is_
          needed, there is no possibility in HTML.

          What you can do is:
          - use a disabled field
          - add a hidden field with the same value
          - when processing the form check for the disalbled field; if it is not
          submitted take the hidden one.

          I filed that problem to the W3C list in december:



          and got an interesting answer from Jukka K. Korpela:



          HTH
          Markus


          Comment

          Working...