-2

How to protect user to clear checkbox using javascript ?

I want to protect clear checkbox from user using javascript

(not use disabled tag) How can i do that ?

<input type="checkbox" id="c1" checked> Do not uncheck
2
  • as long as you know if it was checked (or) not, set that value again in the clickhandler Commented Sep 12, 2014 at 16:57
  • 4
    why display a checkbox at all, then? Commented Sep 12, 2014 at 16:59

1 Answer 1

0

Not sure why you'd want a checkbox that can't be unchecked but you can simply do this:

$(".dontUncheck").click(function(e){
   e.preventDefault();
   $(this).prop("checked", "checked");
});

<input type='checkbox' checked  class="dontUncheck" />

Here's the fiddle: http://jsfiddle.net/0x9vp6ca/

Sign up to request clarification or add additional context in comments.

6 Comments

How to add id="c1" into javascript tag
you can just change the click handler to this: $("#c1).click(... and it will listen to the checkbox with id c1
When checkbox id="c1" not check , i don't checked checkbox ?
I am not sure i understand your question
when checkbox id="c1" checked , user not clear #######but when checkbox id="c1" clear , user can checked
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.