Skip to content

Instantly share code, notes, and snippets.

@cam-gists
Created August 20, 2012 15:52
Show Gist options
  • Select an option

  • Save cam-gists/3405320 to your computer and use it in GitHub Desktop.

Select an option

Save cam-gists/3405320 to your computer and use it in GitHub Desktop.
JQuery: Form Serialization
$('.btn').click(function(){
var inputs = $('[type=text]');
var pw = $('[type=password]');
var checkboxes = $('[type=checkbox]:checked');
var selects = $('option:selected');
// next translate that into an array of just the values
var password = $.map(pw, function(elt, i) {
return $(elt).val();
});
var sels = $.map(selects, function(elt, i) {
return $(elt).val();
});
var inps = $.map(inputs, function(elt, i) {
return $(elt).val();
});
var checks = $.map(checkboxes, function(elt, i) {
return $(elt).val();
});
console.log("SELECTS : " + sels);
console.log("INPUTS : " + inps);
console.log("CHECKS : " + checks);
console.log("PW : " + password);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment