Skip to content

Instantly share code, notes, and snippets.

@cedeber
Created April 3, 2018 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cedeber/8b00d6980ff31152b06207b0160afbe4 to your computer and use it in GitHub Desktop.
Save cedeber/8b00d6980ff31152b06207b0160afbe4 to your computer and use it in GitHub Desktop.
Serialize Form
function serialize(form) {
const inputs = form.querySelectorAll("input");
const fields = {};
for (const input of inputs) {
if (input.name && !input.disabled && input.type !== "file" && input.type !== "reset" && input.type !== "submit" && input.type !== "button") {
if ((input.type !== "checkbox" && input.type !== "radio") || input.checked) {
fields[input.name] = input.value;
}
}
}
return fields;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment