Multiple Check Checkbox
28th March 2008
As I am nearing the end of my initial development phase of BackendPro there’s some useful bits of code I came up with to handle annoying but simple tasks. Over the next week or so I will be releasing a lot more small applications and libraries but felt this may help a few people. Its a small script to check and un-check multiple html check boxes. Its prime use is to save the user time from having to check/un-check many check boxes. It uses jQuery and is only 1/2 lines long.
$("input[name='all']").change(function(){
var parent = $(this);
$("input[name='"+parent.val()+"[]']",parent.parents('form:first')).each(function(){$(this).attr('checked',parent.is(':checked'));});
});
All you need to use it is the following HTML code.
<form> <input type="checkbox" name="all" value="myitems"> <input type="checkbox" name="myitems[]" value="1"> <input type="checkbox" name="myitems[]" value="2"> <input type="checkbox" name="myitems[]" value="3"> </form>
So when the user clicks on the check box with name all, all check boxes with the name specified in the value attribute of this ‘all‘ check box will be toggled. I hope someone finds it helpful.
Posted in Web Development, jQuery