temporary_user_name
temporary_user_name

Reputation: 37078

How to ignore clicks for checkboxes?

I need to attach a function to a checkbox so that clicking it does nothing. How is this possible? I don't want it to be greyed out, I just want to stop it from being togglable.

Upvotes: 4

Views: 4778

Answers (5)

crstamps2
crstamps2

Reputation: 614

I am not sure if this is exactly what you want but this disables the checkbox using JQuery.

$('#checkboxId').attr('disabled', true);

For a non-grey out solution:

$("input:checkbox").click(function() { return false; });

Upvotes: -1

Saigitha Vijay
Saigitha Vijay

Reputation: 466

try this,

 <input type="checkbox" onChange="return checkChange(this)" id="checkid"/>
function checkChange(obj)
  {

 obj.checked=false;
}

Upvotes: 0

Willem
Willem

Reputation: 5404

$('input[type=checkbox]').click(function(){return false;});

just return false on click event, working sample: http://jsfiddle.net/Sh8Zu/

Upvotes: 0

John Lucabech
John Lucabech

Reputation: 156

Try something like this:

<input type="checkbox" onClick="this.checked=!this.checked" />

Upvotes: 6

Jeremy Blalock
Jeremy Blalock

Reputation: 2619

If you want it to be toggleable, just attach an event listener as follows:

$('#checkboxId').on('click', function(e) {
    e.preventDefault();
    e.stopPropagation();
});

Note: This is the same effect as returning false:

$('#checkboxId').on('click', function(e) {
    return false;
});

Upvotes: 8

Related Questions