Skip to content

Instantly share code, notes, and snippets.

@morbidcamel101
Created October 30, 2016 09:41
Show Gist options
  • Select an option

  • Save morbidcamel101/907a7a729e24b8bbd4bdbd6ef211d32d to your computer and use it in GitHub Desktop.

Select an option

Save morbidcamel101/907a7a729e24b8bbd4bdbd6ef211d32d to your computer and use it in GitHub Desktop.
Get Form Object in JQuery (with checkboxes!)
function getFormObj($form) {
var formObj = {};
var inputs = $form.serializeArray();
inputs = inputs.concat(
$form.find('input[type=checkbox]').map(
function () {
return { "name": this.name, "value": this.value }
}).get());
$.each(inputs, function (i, input) {
formObj[input.name] = input.value;
});
return formObj;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment