Solved

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

Posted on 2012-04-02
7
260 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

 

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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

Find out what you should include to make the best professional email signature for your organization.
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 style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

688 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