Pages

19.11.10

jquery detecting checkbox status, checked or not, true or false

when html checkbox is checked, element "checked" will be added to it, and when its unchecked this element will be removed. so to know whether its cheked or not we need to know whether it has the element checked or no.

and to find this out:


<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script>
$(function()
alert($("#test").attr("checked"));
});
</script>
<input type="checkbox" id="test" />

this code will either show us true or false, we can use if statement like that:


<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script>
(function() {
if($("#test").attr("checked")) {
alert("its checked");
} else {
alert("its not checked");
}
});
</script>
<input type="checkbox" id="test" />

if you have any question, comment.

1 comment:

best ed pills said...

Thanks for ones marvelous posting! I really enjoyed reading it, you could be a great author. I will make certain to bookmark your blog and definitely will come back in the foreseeable future. I want to encourage yourself to continue your great posts, have a nice morning!