[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 264
  • Last Modified:

Looking to fire an event when a user unchecks a checkbox.

Looking to fire an event when a user unchecks a checkbox.

By default the checkbox is unchecked, if the user checks then unchecks the box an alert fires.
0
yando18
Asked:
yando18
1 Solution
 
ansudhindraCommented:
you can use onclick event on checkbox..
and use
if(document.getElementById('cbox').checked)

to check if it is checked or unchecked.
0
 
StingRaYCommented:
Try this:

http://jsfiddle.net/zCvex/
function checkme(o) {
    if (!o.checked) {
         alert("Oops! I'm unchecked!");        
    }
}¿

Open in new window

<label for="chk"><input id="chk" type="checkbox" onclick="checkme(this)"> I am checkbox</label>¿

Open in new window

0
 
ProculopsisCommented:
Take a look at this jsfiddle

Code is:

function eventUnchecked() {
    alert("Unchecked");
}

$("#monitor").change(function() {
    if ($(this).is(":checked") == false) eventUnchecked();

});

Open in new window

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
yando18Author Commented:
This is what I have based upon some of your comments. Sorry I should have clarified, I'm using mootools, so would this be correct or should I use something else besides ".match"
           
            var checkEmail = $$('input#vz-email-1');
            checkEmail.addEvent('change', function(e){
                        if ($(this).match(":checked") == false) {
                    alert('test');
                }
                  });
0
 
StingRaYCommented:
It is working fine. http://jsfiddle.net/tgZJy/1/
Or you can use just
var checkEmail = $$('input#vz-email-1');
checkEmail.addEvent('change', function(e){
    if ($(this).checked == false) {
        alert('test');
    }
});¿

Open in new window

0
 
yando18Author Commented:
Sorry Proculopsis, I meant to give you some of the credit as well. Is there a way to update?
0
 
StingRaYCommented:
Send a request to moderator to reopen the question and adjust the point distribution.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now