Last active
August 29, 2015 14:02
-
-
Save Fauntleroy/d12bcf8e5f82bf5c4ec9 to your computer and use it in GitHub Desktop.
Poopy lil' form value parser
This file contains 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
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