Skip to content

Instantly share code, notes, and snippets.

@jmacqueen
Last active August 29, 2015 14:26
Show Gist options
  • Save jmacqueen/aa4a831628a88dcfa019 to your computer and use it in GitHub Desktop.
Save jmacqueen/aa4a831628a88dcfa019 to your computer and use it in GitHub Desktop.
// jQuery-free form values
// Should work in IE9+
var frm = document.querySelector('form'); // Must return containing form
var valueHash = Object.keys(frm.elements).slice(frm.elements.length + 1).reduce(function(a,key){
var elm = frm.elements[key];
if(elm.type !== "checkbox" || elm.type == "checkbox" && elm.checked !== false) {
a[key] = elm.value;
}
return a;
},{})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment