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.
yando18Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
StingRaYConnect With a Mentor Commented:
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
 
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
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
 
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
 
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
All Courses

From novice to tech pro — start learning today.