...

View Full Version : readonly checkbox - is it possible ?



steveg
06-27-2005, 05:28 PM
Is it possible, using thin client technology to create a standard html checkbox readonly, not disabled - just read only.

Any help would be greatly appreciated here.

Thanks in advance

Steve.

mark87
06-27-2005, 06:30 PM
Yes you can use the readonly property -

<input name="chkbox1" type=checkbox readonly>check box 1

... I don't see the point of it though.

mrruben5
06-27-2005, 09:29 PM
if you want to be sure to use valid markup, use this:

<input readonly="readonly">

steveg
06-28-2005, 08:54 AM
they don't work.

What I'm after is basically a copy of an html form that has already been filled in, its being sent over email and Its a legal requirement that the emailed form be totally readonly. This solution does not work, in any respect by the looks of it.

Thanks

Steve.

_Aerospace_Eng_
06-28-2005, 09:25 AM
Why can't you use a hidden value?
<input type="hidden" value="somevalue">
I'm not even sure if you can use readonly with a checkbox. You might have to use some javascript.
<input type="checkbox" checked="checked" onclick="return false" onkeydown="return false">

Bill Posters
06-28-2005, 09:41 AM
Its a legal requirement that the emailed form be totally readonly.
A pre-filled, read-only form isn't a form at all, it's just a regular document.
If the content isn't intended to be edited, why bother using form elements?

mark87
06-28-2005, 11:57 AM
My thoughts exactly... rethink about what you need to do.

And yes you can 'readonly' a checkbox... but it's irrelevant, hence why I said I didn't see the point. In checkboxes it's either on or off, you don't change the 'value' asuch, that's why the readonly property is best suited to elements such a text boxes.

_Aerospace_Eng_
06-28-2005, 07:00 PM
Mark have you tried to make checkbox readonly using only the readonly property? It doesn't let you at least not this way

<input type="checkbox" readonly checked="checked">

or this way

<input type="checkbox" readonly="readonly" checked="checked">

You can however have it checked and make it disabled

<input type="checkbox" disabled="disabled" checked="checked">

but since the user is probably using this for the wrong reasons then this may be irrelevant.

mark87
06-28-2005, 07:04 PM
I haven't experimented with it as I didn't need to lol, but yes much better to disable a checkbox... or even better to make it hidden.

sesshyzkidz
06-28-2005, 07:06 PM
Um. . .

If none of those work for you, I suggest creating a small checkbox image. That'll make it read-only.

Edit: nevermind. I didn't realize you wanted to send it through e-mail. . .

Bill Posters
06-28-2005, 09:59 PM

You can however have it checked and make it disabled

<input type="checkbox" disabled="disabled" checked="checked">

Disabling is not really an option when trying to 'lock' the value of a form element. The data contained in a disabled form element isn't passed forward to be processed. It is simply ignored.

Rumplestiltzkin
02-20-2007, 07:44 AM
I can think of any number of reasons why you might want to do this. I have come across this thread because, in my case, I want to display truth values stored in a database in a table (not a form), and a readonly checkbox would be very useful. Also, what if forms that have been entered by one person need to be sent to another for appoval? The approver must certainly _not_ be able to change any entered data, only approve or deny the previously submitted data.
And what about dynamic forms where the checkbox is only relevant if another value elsewhere has already been entered, selected, checked, etc.? You may always want a result from the checkbox regardless of whether the use was able to check it or not.

So I tried all the suggestions here and absolutely none worked. The idea of an image would certainly work, but it is an almighty pain because checkboxes look different in different browsers and you want a consistent look and feel, this is very hard to achieve without having different images for every possible browser!

What you want is the kind of image you get in Windows form when a checkbox is readonly, i.e. it is greyed out.

So if anyone has any suggestions, I'd be extremely grateful.

Karen S. Garvin
02-20-2007, 03:13 PM
you want a consistent look and feel,

What about creating a PDF file? You won't need to worry about the checkboxes or graphics on the client's end.

andrewmta
02-20-2007, 10:54 PM
what if forms that have been entered by one person need to be sent to another for appoval? The approver must certainly _not_ be able to change any entered data, only approve or deny the previously submitted data.

Wouldn't it make more sense to display the value of the data as text and then just add a "Approve" submit button. If content is never designed to be edited, then it doesn't need to be in an input.



And what about dynamic forms where the checkbox is only relevant if another value elsewhere has already been entered, selected, checked, etc.? You may always want a result from the checkbox regardless of whether the use was able to check it or not.

This situation is what the disable feature in a form is for. You may use Javascript to disable a form field until another is completed etc.

All of this sounds like you're trying to use form inputs to do something that there is better ways of doing. Both the readonly and disabled code listed above worked for me by the way.

Rumplestiltzkin
02-21-2007, 01:17 AM
Wouldn't it make more sense to display the value of the data as text and then just add a "Approve" submit button. If content is never designed to be edited, then it doesn't need to be in an input.

Not if you want the approval form to look the same as the data entry form. This is clearer for users.


All of this sounds like you're trying to use form inputs to do something that there is better ways of doing.

Yes & no. I just like the look of the checkbox. I could display text values (Yes/No, True/False), but a checkbox looks better.


Both the readonly and disabled code listed above worked for me by the way.

Well not for me. Readonly (in Firefox) just gives you a regular checkbox which is editable, tabable, etc. Disabled blanks the value whether it's checked or not. I think it works in IE, but I'm sure we've all been burned by taking advantage of Microsoft's non-standard extensions!


This situation is what the disable feature in a form is for. You may use Javascript to disable a form field until another is completed etc.

I understand this, but using disabled has disadvantages:

the value does not get submitted with the form; there are times when you may want to capture (or re-capture) the value even though the user cannot edit it.
some browsers blank out the checkbox when it is disabled, thus preventing you from displaying a value.

The point is you don't always want to actually disable an input, just stop the user from making further changes.

Rumplestiltzkin
02-21-2007, 01:52 AM
I've given up on this. It's clear that a checkbox is primarily an input HTML element rather than a more generic one - the fact that it's an input tag is probably a bit of a hint to this :p - and has never been seriously considered as a display element. I had hoped to use the "fitting a square peg into a round hole by cutting off the corners" technique - of which I am so fond :D - but clearly even this is not possible, at least not if I want multiple browser support and I want to do it in 5 minutes.

So thanks for the suggestions/discussion. I'll be going back to using text values.

bitbob
02-21-2007, 08:42 AM
oh come on don't give up... just use a regular checkbox and a bit of javascript. Check the original value (on or off) then set the value to the original value onchange()...

Bill Posters
02-21-2007, 08:54 AM
oh come on don't give up... just use a regular checkbox and a bit of javascript. Check the original value (on or off) then set the value to the original value onchange()...
Js can be disabled or may not be supported by a user's UA. Because of this, it's rarely a good idea to rely on it to do jobs such as managing form interactions (unless you can be 100% certain that every user will have js enabled UAs - e.g. an intranet / company office computer).

bitbob
02-21-2007, 05:07 PM
i know there's probably workarounds for this too, but not too many out there are manipulating post headers and such, but I rely heavily on JS and kick people out if they don't have it enabled. It's easy enough to manipulate the page with javascript and add content to the page. If that content isn't present after the form beeing submitted - kick the user out.

JohnDubya
02-21-2007, 05:34 PM
If somebody doesn't have JS enabled, they should be tarred and feathered. I wouldn't be too concerned about appealing to these people anyway. Just make it so if someone has JS disabled, your script will kick them off your site, like bitbob said. :)

Bill Posters
02-21-2007, 06:26 PM
How very late-'90s of you.

Sorry, but that's an out-dated attitude and not one which I'd recommend anyone taking seriously, at least, not those producing professional-grade sites.

There are a significant number of people out there who, for whatever reason, may not be using a js-enabled UA.
Some people may be working in offices where IT have disabled js. Some users may be using assistive technologies which don't support js. Some may be using mobile devices which don't support js well or at all.

If you are at all serious about accessibility, then you'll appreciate why ensuring that a site works w/o js is a good thing.

http://www.w3.org/TR/WCAG10-HTML-TECHS/#scripts-gt


Take the time to learn about best practice. Your users and clients (and their users) will thank you for it.


Of course, if it's just a simple DIY site with no real aspirations towards effectiveness, do as you wish. No-one is likely to notice or care.

JohnDubya
02-21-2007, 06:40 PM
Guess I have this attitude because I haven't been involved in any professional-grade site yet. That's my bad...I've just been under the opinion that if a user had Javascript disabled, he or she didn't really know what he or she was doing. I guess it seems like most Javascript security risks have been taken care of, but I guess that may not be the whole truth. Thanks for the info, Bill.

bitbob
02-22-2007, 08:20 AM
Bill Posters: As I said I rely on JS and do kick people out that doesn't have it enabled. I also do work proffesionaly, and almost all sites I do uses ajax... I do not design nor code for people that have JS disabled. Either they're the ones outdated or they are up to no good.

Accessibility is for sites that is for everyone, and I do meen everyone. I honestly don't care about everyone, and don't code sites for everyone, so I don't need to care about accessibility either.

We do have people at out company that code for the masses. They use js as well, but it's ok not to have it enabled. I on the other hand work with more complex stuff (if you find coding more complex than designing, since my work isn't too beautiful ;) ) and arn't informational sites, but usable applications for groups of people.

Not everything should be accessible, not everything should have top ratings in google. Everything should follow standards though, and you should design and code for the specific groups that you aim at.

Tell me how I should create ajax sites without javascript enabled.

edit: btw, while this site still works with js disabled, it's not very accessibile since many things doesn't work anymore. Menu options are visible, but you can't click on them.

JohnDubya
02-22-2007, 03:27 PM
I just got through with a CSS class, and they said to always make sure you know who your audience is. If your audience is more computer-competant users, you can do a lot more. If you expect to have older and less computer-competant people use your site, you should definitely pay special attention to accessibility and user-friendliness (like not using a ton of JS). But some good points made, thanks. :)

Bill Posters
02-22-2007, 04:28 PM
http://www.google.co.uk/search?q=hijax

(Consider yourself lucky, bitbob. The much lengthier, original version of this post I was making went awol, so you get the much abridged version.) ;)

bitbob
02-22-2007, 04:54 PM
Hehe... Thanks for the link... I get your point. But I don't think it's profitable for me to do stuff like that. Project will grow to much in developing time for the benifit of too few users (til this day, we've only got complains from people (2 or 3 tops) that had js disabled but didn't know about it).

veenutk
06-11-2007, 05:20 PM
Have a checkbox as follows:

<input type="checkbox" name="checkbox" OnClick="javascript:return ReadOnlyCheckBox()" />

Support the above with JavaSript as:
<script language="javascript" type="text/javascript">
function ReadOnlyCheckBox()
{
return false;
}
</script>

The above checkbox will not allow the user to change the state and even it will not appear in the Grey background (as Disabled). -courtesy http://forum.java.sun.com/thread.jspa?threadID=159711&messageID=472005

does this help?

whizard
06-11-2007, 05:32 PM
..and then I turn off JS and click your textbox, and presto, the value changes

Dan

Bill Posters
06-11-2007, 06:34 PM
Hehe... Thanks for the link... I get your point. But I don't think it's profitable for me to do stuff like that. Project will grow to much in developing time for the benifit of too few users (til this day, we've only got complains from people (2 or 3 tops) that had js disabled but didn't know about it).
(I know this is an old thread, but in case you're still reading posts here…)

It's worth noting that the vast majority of people who find obstacles on sites typically don't complain, they leave. It's far from safe to assume that because only 3 people complained, only 3 people had a problem.
You may not be aware of how many people are effected or even leaving due to the site's dependence upon js.

If the idea of developing a site that works without js seems too costly, then chances are, you've got it wrong from the start.

Also, it's not simple a profit issue. You should consider what accessibility legislation is in effect in not only your own jurisdiction, but also those jurisdictions into which the service extends.

whizard
06-11-2007, 08:30 PM
Also, it's not simple a profit issue. You should consider what accessibility legislation is in effect in not only your own jurisdiction, but also those jurisdictions into which the service extends.

I agree with you about accessibility, but I was just wondering (from a purely intellectual interest) what 'those jurisdictions into which the service extends' can do about your website not meeting their standards?

Dan

Arbitrator
06-11-2007, 09:31 PM
If interested, the Mozilla bug number for this issue is 88512 (https://bugzilla.mozilla.org/show_bug.cgi?id=88512). Seems that they’ve relegated it to the status of “enhancement”; personally, I think that this feature is defined (vaguely) by the HTML 4.01 specification and should not be considered as an enhancement.


Have a checkbox as follows:

<input type="checkbox" name="checkbox" OnClick="javascript:return ReadOnlyCheckBox()" />There is no OnClick attribute in XHTML. All XHTML attribute names are defined in lowercase. You shouldn’t use javascript: in an event attribute either; the correct way to define that an event attribute is of a certain language is through the Content-Script-Type HTTP header or the equivalent meta element.


Support the above with JavaSript as:
<script language="javascript" type="text/javascript">Avoid the language attribute.


..and then I turn off JS and click your textbox, and presto, the value changesYeah, I think that if it’s really desired that the data be read‐only, then it should be displayed as plain text.


I agree with you about accessibility, but I was just wondering (from a purely intellectual interest) what 'those jurisdictions into which the service extends' can do about your website not meeting their standards?People might be able to sue to you. I believe that target.com was sued over their Web site not having things like alt attributes. Not sure what became of the case though. Anyway, I don’t know of any legislation that requires no‐JavaScript accessibility nor do I think that people would sue a small‐site owner.

Bill Posters
06-11-2007, 10:15 PM
I agree with you about accessibility, but I was just wondering (from a purely intellectual interest) what 'those jurisdictions into which the service extends' can do about your website not meeting their standards?

Dan

Computer-based exam discriminated against blind candidate (http://www.out-law.com/page-7692)

OUT-LAW News, 24/01/2007

A qualifications body discriminated against a blind systems manager when it failed to make its computer-based exam accessible to her. The tribunal ruling is the first to find a US company with no presence in the UK liable under the UK's Disability Discrimination Act.



It surprised me too.

whizard
06-16-2007, 01:51 AM
Thanks Arbitrator and Bill for digging that up! Interesting..

I guess I'm still wondering, after reading the article Bill posted, even though PMI was ordered to pay the woman, so what? They do no business in the UK, so why did they even bother to participate in the legal proceedings?

They've been ordered to pay her, but that's like your friend's mom telling you you have to go inside when it gets dark out.

Now, please understand, I believe in being nice, and making pages accessible.

Still, I'd be interested in hearing, from anyone who knows anything about law, why PMI should care at all what a court in the UK says?

Thanks
Dan

(Complete Threadjack going on here - sorry :p)

scrupul0us
06-16-2007, 05:22 AM
set the checkbox to checked and tell javascript to onFocus=this.Blur

check for JS first and tell them in order to use the site JS must be enabled

done and done

whizard
06-16-2007, 05:29 AM
Yes, there are a slew of javascript solutions, but the point is that ANY javascript solution can be easily bypassed.

Dan

Cablestein
04-15-2010, 06:14 PM
MY SOLUTION... NO JAVASCRIPT... plain as day

I came to this thread with a similar problem as OP.

Needed to display a form element as greyed-out (unchangeable) but still pass it in the form upon submission.

WHY? So I could maintain a consistent look to my form. A particular checkbox needed to be greyed-out for some users, and they need to be SHOWN that it's greyed out.

Some people mentioned making an image of a greyed-out checked checkbox, but this solution breaks considering form styling changes across different browsers and OS's.

Also, the "readonly" property for a form doesn't seem to work in my Firefox (FF3 3.6, Max OSX 10.4.11).

What I did:
Use a dummy checkbox to visually display a greyed out checked box. Since it is set to "disabled", it won't pass on submit. Then have a hidden form element right after that passes the true locked variable on submission.

<input type='checkbox' name='dummy1' value='1' disabled checked>
<input type='hidden' name='group1' value='1' checked>

Works for me just fine!

Arbitrator
04-16-2010, 06:37 AM
If interested, the Mozilla bug number for this issue is 88512 (https://bugzilla.mozilla.org/show_bug.cgi?id=88512). Seems that they’ve relegated it to the status of “enhancement”; personally, I think that this feature is defined (vaguely) by the HTML 4.01 specification and should not be considered as an enhancement.


Also, the "readonly" property for a form doesn't seem to work in my Firefox (FF3 3.6, Max OSX 10.4.11).It seems that I was mistaken three years ago as it appears that the HTML 4.01 spec does not permit this behavior; it states that the |readonly| attribute of |input| elements is "for text and passwd".

HTML5 maintains this restriction [2] though it does so much more explicitly: "the following content attributes must not be specified and do not apply to the element: [...], |readonly|, [...]."

I'm still not sure why the restriction exists.


What I did:
Use a dummy checkbox to visually display a greyed out checked box. Since it is set to "disabled", it won't pass on submit. Then have a hidden form element right after that passes the true locked variable on submission.

<input type='checkbox' name='dummy1' value='1' disabled checked>
<input type='hidden' name='group1' value='1' checked>

Works for me just fine!I'd guess that the use of the |checked| attribute for the |type="hidden"| element is unnecessary here and simply being ignored; I suspect that the value |1| will be submitted regardless of whether or not that attribute is present. So, it looks like you can just drop the attribute and save yourself a bit of code.

Both the HTML 4.01 [3] and HTML5 [4] specs say that the attribute should be ignored while HTML5 goes further and says that the attribute "must not" be used for |type="hidden"| elements.

The HTML 4.01 spec says that "when the |type| attribute has the value "radio" or "checkbox", [the |checked| attribute] specifies that the button is on. User agents must ignore this attribute for other control types" whereas the HTML5 spec says that "the following content attributes must not be specified and do not apply to the element: [...], |checked|, [...]."

[1] http://www.w3.org/TR/html401/index/attributes.html#h-3
[2] http://www.whatwg.org/specs/web-apps/current-work/multipage/number-state.html#checkbox-state (2010 April 16 Working Draft)
[3] http://www.w3.org/TR/html401/interact/forms.html#adef-checked
[4] http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#hidden-state (2010 April 16 Working Draft)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum