Skip to content

Instantly share code, notes, and snippets.

@Fauntleroy
Last active August 29, 2015 14:02
Show Gist options
  • Save Fauntleroy/d12bcf8e5f82bf5c4ec9 to your computer and use it in GitHub Desktop.
Save Fauntleroy/d12bcf8e5f82bf5c4ec9 to your computer and use it in GitHub Desktop.
Poopy lil' form value parser
var dom = require('domquery');
var domready = require('domready');
var forEach = Array.prototype.forEach;
var getFormData = function( form ){
var form_data = {};
forEach.call( form.elements, function( el, i ){
switch( el.tagName ){
case 'INPUT':
case 'TEXTAREA':
case 'SELECT':
form_data[el.name] = el.value;
break;
}
});
return form_data;
};
domready( function(){
var $form = dom('#configuration');
$form.on( 'submit', function( event ){
event.preventDefault();
var form_data = getFormData( $form[0] );
console.log( 'form_data', form_data );
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment