Posts Tagged ‘jquery’
Checking all your checkboxes with jQuery
Ok I know this blog is geared towards ExtJS and I do expect you to lambast me for posting jQuery code snippets but, in my free time one lunch time I decided what it would be like to rewrite the ExtJS vertical checkbox examples I’ve been posting using jQuery.
Turns out, there’s not a great deal of difference in the length of the code, maybe the clarity and readability is slightly improved with jQuery, although looking at it there’s not a great deal in it. So for shits n giggles here’s my jQuery code:
<script type="text/javascript">
$(document).ready(function(){
$("#select_none").click(function(){
$(":checkbox").attr("checked", false);
$("#update_button").attr("disabled", true);
return false;
});
$("#select_all").click(function(){
$(":checkbox").attr("checked", true);
$("#update_button").attr("disabled", false);
return false;
});
// clear all checkboxes.
$("#select_none").click();
$(":checkbox").click(function(){
if($(this).attr("checked") == true)
{
if($("#update_button").attr("disabled")==true)
$("#update_button").attr("disabled", false);
}
else
{
if($(":checked").length == 0)
{
$("#update_button").attr("disabled", true);
}
}
})
});
FYI if you’re interested in checking out jQuery in more detail, have a look at the post over on Ajaxian filled with jQuery videos presented by John Resig himself.