Share
ShareSidebar
2011-09-28 13:14:38 +1

Jquery, how to check if a checkbox is checked

If the checkbox is checked, then I need to show an Alert, in Jquery.

Rate this post

You must be registered to vote first

Comments

jzentt
jzentt 2011-09-28 13:46:01

Try this:

Html

        <table>
           
<tr>
               
<td><input type="checkbox" class="test_checkbox" value="1" />Value 1</td>
           
</tr>
           
<tr>
               
<td><input type="checkbox" class="test_checkbox" value="2" />Value 2</td>
           
</tr>
       
</table>

Jquery

       <script type="text/javascript">
            $
(document).ready(function(){
               
//Example 1
                $
('.test_checkbox').click(function(){
                   
if ($(this).attr('checked')) {
                        alert
("Checked - Value:"+$(this).attr('value'));
                   
}else{
                        alert
("Unchecked - Value:"+$(this).attr('value'));
                   
}
               
});
               
//Example 2
                $
(".test_checkbox").click(function(){
                   
var thisCheck = $(this);
                   
if(thisCheck.is(':checked'))
                   
{
                        alert
("Checked - Value:"+$(this).attr('value'));
                   
}else{
                        alert
("Unchecked - Value:"+$(this).attr('value'));s
                   
}
               
});
           
});
       
</script>
+0

Comment