Skip to content

Instantly share code, notes, and snippets.

@devth
Created August 12, 2010 16:39
Show Gist options
  • Save devth/521255 to your computer and use it in GitHub Desktop.
Save devth/521255 to your computer and use it in GitHub Desktop.
// TRENT RICHARDSON
// http://trentrichardson.com/2009/01/08/getting-a-list-of-checkbox-values-with-jquery/
jQuery.fn.getCheckboxVal = function(){
var vals = [];
var i = 0;
this.each(function(){
vals[i++] = jQuery(this).val();
});
return vals;
}
// EXAMPLE
var arr = $("input[name='fieldname']:checked").getCheckboxVal()
//would return an array like:
// ['val1', 'val2', 'val3']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment