sgerbhctim
sgerbhctim

Reputation: 3640

jquery on click checkbox issue

Here is the Fiddle.

So I've set up this little example of what I am trying to do. I want this checkbox to work as the following. When user tries to enable/click the checkbox (mostly for people who are not computer savvy), I would like for it to alert them saying "You must login to do this action".

I can't figure it out. I've been searching all over for an answer, and couldn't find one.

Thanks a lot in advance for all your answers!

Upvotes: 3

Views: 65

Answers (2)

j08691
j08691

Reputation: 207901

Remove the checked and disabled attributes and use this code:

$(".check").click(function() {
    if ($(this).is(':checked')) alert("You must sign in to do this.");
});​

jsFiddle example

Upvotes: 0

João Silva
João Silva

Reputation: 91299

Simply remove the disabled attribute from the checkbox. Also, if you want to show the alert only when the checkbox gets checked, use the following instead:

$(".check").click(function() {
    if (this.checked) {
        alert("You must sign in to do this.");
    }
});

Upvotes: 4

Related Questions