Ber53rker
Ber53rker

Reputation: 1038

Prevent CheckBox check when clicking it's text?

In other words, I want it so when you click the text on the checkbox it doesn't get checked. It only checks when you click the actual checkbox. I've tried many things, but have come up empty. It seems it will fire all the events no matter what. (Click, Checked, Focus) Maybe a way to prevent or override the default event functions? Thanks.

Upvotes: 0

Views: 1804

Answers (2)

graham mendick
graham mendick

Reputation: 1839

Setting a label's for attribute to point at the checkbox id is what causes the checkbox to get selected when the text is clicked.

<label for="checkboxId">test</label><input type="checkbox" id="checkboxId"/>

So, you could just remove the for attribute, but this is inadvisable from an accessibility perspective

Upvotes: 0

Ryan
Ryan

Reputation: 1797

Instead of writing the text in the checkbox control itself, add a label next to it with the caption.

So you would have:

[label caption] []

Clicking on the label caption would have no effect on the checkbox.

Upvotes: 3

Related Questions