How to detect that a user has unchecked a checkbox?

ADM picture ADM · Jan 27, 2011 · Viewed 11.7k times · Source

The following form:

    <form action="x.php" method="get" id="myForm">Subscribe:
<div id="radioButtonsWithAdds">
    <input type="radio" name="group1" value="one">One month 2,99$  
    <input type="radio" name="group1" value="two"> Two months   5,98$</div><br>
    <input type="checkbox" name="option1" value="withAdds" checked>  with adds
    <img src="next.png" border="0" alt="enviar" onclick="document.getElementById('myForm').submit();"> 
    </form>

Is the first part of a subscription from. In here, the user may choose between one month or two months subscription.

If the user agrees to receive adds, leaves the checkbox checked, that will be all, he/she can hit the next button and it's ok.

But if the user unchecks the "with adds" checkbox, a div will show in the place of the #radioButtonsWithAdds one containing another set of radio buttons with different prices.

How can I detect that the checkbox ish without hitting any submit button?

Answer

alex picture alex · Jan 27, 2011
$('#yourcheckbox').change(function() {

   if ( ! this.checked) {
       // It is not checked, show your div...

   }

});