Can HTML checkboxes be set to non editable?

Programming for Search Engines 101. An area for avid PHP and .NET developers to chat about Programming techniques and how to make better use of search engines.

Moderator: Moderators

Can HTML checkboxes be set to non editable?

Postby josmy » Thu Mar 14, 2013 1:24 am

Yes, it's possible.

There may be situations like where we want to restrict user to change the selected value of a check box, especially on edit form pages,

After doing much googling, i found the following solutions.

Method -1
----------------
Just add disabled="disabled" as attribute.
<input type="checkbox" disabled="disabled" checked="checked">

* The disadvantage is, while submitting this form, server page won't get the value from a disabled control.

Method - 2 - ( feasible method for me)
------------------------------------------------
Just add both [onclick="return false"] and [onkeydown="return false"] attributes.
<input type="checkbox" onclick="return false" onkeydown="return false" checked="checked" />

Thanks friends, hope this would be helpful in your development time.
josmy
 
Posts: 3
Joined: Fri Aug 26, 2011 12:45 am
Tell us why you would like to become a WyseLabs Member:

Re: Can HTML checkboxes be set to non editable?

Postby beniston » Thu Mar 14, 2013 6:59 am

Yes it is. This will remind a web develop in time of a need like this. Thanks :)
beniston
 
Posts: 502
Joined: Wed Nov 02, 2011 4:35 am
Location: Cochin
Tell us why you would like to become a WyseLabs Member:


Return to Programming

Who is online

Users browsing this forum: No registered users and 7 guests