Skip to content

Instantly share code, notes, and snippets.

@blackjid
Created May 7, 2012 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blackjid/2628871 to your computer and use it in GitHub Desktop.
Save blackjid/2628871 to your computer and use it in GitHub Desktop.
A clean way to get data from a form element using the submit event
//Requires underscore, jquery
$(document).on('submit', 'selector.to.the.form.element', function(e){
// The the data from the form
var formData = _.reduce($(e.currentTarget).serializeArray(), function(memo, val){
memo[val.name] = val.value;
return memo;
},{});
// HERE YOU CAN USE THE FORM DATA ...
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment