By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,246 Members | 1,401 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,246 IT Pros & Developers. It's quick & easy.

disabled vs readonly input elements

P: n/a

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.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Tue, 6 Jan 2004 14:40:59 -0600, kaeli declared in
comp.infosystems.www.authoring.html:
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.)


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
http://www.clarkecomputers.com.au
Jul 20 '05 #2

P: n/a
Mark Parnell wrote:
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?


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

<http://www.w3.org/TR/2001/CR-css3-selectors-20011113/#UIfragments>
<http://bugzilla.mozilla.org/show_bug.cgi?id=176170>
--
Anne van Kesteren
<http://www.annevankesteren.nl/>
Jul 20 '05 #3

P: n/a
In article <2i****************************@40tude.net>,
we*******@clarkecomputers.com.au enlightened us with...

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?


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.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #4

P: n/a
"kaeli" <ti******@NOSPAM.comcast.net> schrieb im Newsbeitrag
news:MP************************@nntp.lucent.com...
In article <2i****************************@40tude.net>,
we*******@clarkecomputers.com.au enlightened us with...

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?


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.


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:

http://lists.w3.org/Archives/Public/...3Dec/0116.html

and got an interesting answer from Jukka K. Korpela:

http://lists.w3.org/Archives/Public/...3Dec/0117.html

HTH
Markus
Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.