Skip to content

Instantly share code, notes, and snippets.

@kevin-shu
Last active December 16, 2015 21:38
Show Gist options
  • Save kevin-shu/5500715 to your computer and use it in GitHub Desktop.
Save kevin-shu/5500715 to your computer and use it in GitHub Desktop.
function formToData(dom) {
var _this=this,
_i,
data;
if(dom){
_this=dom;
}
fields = _this.querySelectorAll("input, textarea, select");
for(_i=fields.length-1; i>=0; _i--){
var _key = fields[_i].name||fields[_i].id;
if (_key) {
data[_key]=fields[_i].value;
}
}
return data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment