Solved

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

Posted on 2012-04-02
7
255 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Someone recently asked me about how to display a progress indicator on a page while an iframe is loading. And I remember when I first came across this myself. It was a bit tricky to get my head around, but really, it's very simple. The most impor…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

708 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now