Created
March 23, 2016 15:56
-
-
Save seanmavley/afa1844636d03cc0377e to your computer and use it in GitHub Desktop.
gather all form elements
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
<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