Skip to content

Instantly share code, notes, and snippets.

@seanmavley
Created March 23, 2016 15:56
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 seanmavley/afa1844636d03cc0377e to your computer and use it in GitHub Desktop.
Save seanmavley/afa1844636d03cc0377e to your computer and use it in GitHub Desktop.
gather all form elements
<script>
(function() {
var form = document.getElementById('form_837299');
form.addEventListener('submit', function(event) {
// Prevent normal form submit
event.preventDefault();
});
document.getElementById('saveForm').addEventListener('click', function() {
Array.prototype.forEach.call(form.children, function(child) {
var name = child.getAttribute('name');
if ('value' in child && child.type !== 'submit' && name) {
console.log(name, child.value);
// Use jQuery.ajax or a Polymer/core-ajax element to send
// the data to the server
}
});
});
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment