Solved

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

Posted on 2012-04-02
7
258 Views
Last Modified: 2012-04-02
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
Comment
Question by:yando18
7 Comments
 
LVL 13

Expert Comment

by:ansudhindra
ID: 37796522
you can use onclick event on checkbox..
and use
if(document.getElementById('cbox').checked)

to check if it is checked or unchecked.
0
 
LVL 15

Expert Comment

by:StingRaY
ID: 37796583
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
 
LVL 20

Expert Comment

by:Proculopsis
ID: 37796619
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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:yando18
ID: 37797434
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
 
LVL 15

Accepted Solution

by:
StingRaY earned 500 total points
ID: 37797510
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
 

Author Comment

by:yando18
ID: 37797579
Sorry Proculopsis, I meant to give you some of the credit as well. Is there a way to update?
0
 
LVL 15

Expert Comment

by:StingRaY
ID: 37797632
Send a request to moderator to reopen the question and adjust the point distribution.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question