Created
May 7, 2012 16:41
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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