Why would I want to disable a form field... the point of having a form is that users fill it in and then submit it...

Does anybody have any examples of how they have used these attributes on a site?

AutisticCuckoo
—
2010-02-05T13:56:48Z —
#2

Fields can be disabled depending on conditions in the form. When the user changes a condition the field can be enabled, either via JavaScript or via a round-trip to the server.

For instance, you could have a range of radio buttons for various options, where the last one is 'other'. Then you could have a text field where the user could enter supplemental information, and this field could be disabled unless the user has selected the 'other' button.

Readonly fields are useful for presenting information that shouldn't be editable by the user, yet should be part of the form submission. For instance, a user ID field.

Stomme_poes
—
2010-02-05T19:48:17Z —
#3

[ot]

like "I agree to nothing, you owe me your soul", etc.

Wow, awesome! How come I never think to do stuff like that? : ( [/ot]

xhtmlcoder
—
2010-02-05T14:12:52Z —
#4

You may want to "disable" with 'disabled' for a form's submit button until the user has entered some required data to stop undesirable or irrelevant submissions. Disabled elements are "read-only" elements with the added restrictions that the values are not submitted with the form, the elements cannot receive focus, and the elements are skipped when navigating the document by tabbing.

Setting the 'readonly' attribute allows authors to display unmodifiable text in a TEXTAREA. This differs from using standard marked-up text in a document because the value of TEXTAREA is submitted with the form, i.e. 'readonly' stops the user modifying the value. You may want to do that with a password text, etc.

I am not familiar with an attribute called 'enabled' that is NOT an attribute option in plain HTML 4.01.

Divisive_Cotton
—
2010-02-05T14:27:40Z —
#5

Thanks for the responses.

Actually there isn't an enabled attribute. In CSS3 this is just for non-disabled fields

I routinely use readonly on textareas where users need to read some terms and conditions (there's also always another page called terms and conditions where people can punish themselves with reading as well). It's a sort of imitation of the things you agree to before installing some software etc with "check if you're read this" or radio buttons "I agree, I disagree".

I've seen mentioned recently on the forums using disabled for the first option of a select dropdown... where the first option is a bunch of dashes

one reason maybe would be to force users to pick some defined value rather than staying at the default (of course some other form control would be a better choice then).

AutisticCuckoo
—
2010-02-05T18:17:25Z —
#7

xhtmlcoder said:

You may want to "disable" with 'disabled' for a form's submit button until the user has entered some required data to stop undesirable or irrelevant submissions.

It should perhaps be mentioned that this practice only works if JavaScript is enabled and that the submit button should initially be enabled. You could then start by disabling the button with JavaScript and then re-enable it once all required fields are filled in etc. Doing it any other way will cause accessibility issues.

Stomme_poes said:

I routinely use readonly on textareas where users need to read some terms and conditions (there's also always another page called terms and conditions where people can punish themselves with reading as well).

That's one use for them, although a scrolled <div> or suchlike is equally useful. Unless you actually require that the T&C text be submitted with the form, of course.

C_Ankerstjerne
—
2010-02-05T18:28:10Z —
#8

Using the readonly attribute to make sure that the contents of a textarea is submitted in an unaltered state is dangerous. It would be very easy to alter the contents of the textarea, and then submit the altered version. At least in some countries, this could technically be considered legally binding if the webstore does not react to the altered contract (i.e. a counter-offer). Therefore, the readonlytextarea's contents should be checked server-side.

Stomme_poes
—
2010-02-05T19:28:04Z —
#9

Luckily, it doesn't seem to matter to the company if the textarea is submitted.

And, no scrolling divs I think simply because I'd want to keep it a form control in a form (since the terms&conditions are in the middle of a form... yeah also not so smart but that's the way it is). Though I don't remember if readonly was an issue in JAWS, since while I can get focus in there in FF there might have been a browser who didn't allow the focus?? If so then JAWS wouldn't be able to read it. Hm..

xhtmlcoder
—
2010-02-05T19:44:50Z —
#10

Yes, I've fiddled with "terms and conditions" text-areas and submitted them before on online forms that weren't read-only putting things stupid; like "I agree to nothing, you owe me your soul", etc. It's hard to believe many sites still don't stop the user editing them, or double-check, etc.

xhtmlcoder
—
2010-02-05T19:53:47Z —
#11

[ot]

Stomme_poes said:

Off Topic:

Wow, awesome! How come I never think to do stuff like that? : (

Probably because you are more sane. [/ot]

But you can see the problems caused by not thinking it through.

Stomme_poes
—
2010-02-05T20:22:41Z —
#12

But you can see the problems caused by not thinking it through.

I can see Christian's point, for when it matters (as far as I know, the only truly legally binding stuff we have when someone signs up for insurance online is the stuff they get on paper in the mail later).

Is there some other possible issue as well?

C_Ankerstjerne
—
2010-02-05T20:39:34Z —
#13

If the textarea is only submitted, but not stored, I don't see any other issues. If it's stored in the database, however, it will have to be sanitized as well, as it could otherwise be used for SQL injections.

felgall
—
2010-02-05T21:54:20Z —
#14

xhtmlcoder said:

Yes, I've fiddled with "terms and conditions" text-areas and submitted them before on online forms that weren't read-only putting things stupid; like "I agree to nothing, you owe me your soul", etc. It's hard to believe many sites still don't stop the user editing them, or double-check, etc.

Your changing it makes no difference really since the submission page on their site still says the same as it said before your change and that says that by submitting the page you agree to that condition. You clicked the link so you agreed to that condition rather than what you changed it to read. To prove you clicked the link all they need do is to show you had accessed where ever the link goes. What the page said with your modification is irrelevant since that isn't what their page says you have to agree to. So you'll probably find that although you said "I agree to nothing, you owe me your soul" that the reverse is what you actually agreed to by clicking the link in the first place.