Skip to content

Instantly share code, notes, and snippets.

@luozhihua
Created January 3, 2014 02:29
Show Gist options
  • Save luozhihua/8231545 to your computer and use it in GitHub Desktop.
Save luozhihua/8231545 to your computer and use it in GitHub Desktop.
Get all forms value with form element.
var formData = {};
$('#form-ID').find('input,select,textarea').each(function() {
var name = this.name || this.id,
type = (this.getAttribute('type')||'').toLowerCase(),
value;
switch (type) {
case 'radio':
value = this.checked ? this.value : value;
break;
case 'checkbox':
value = formData[name] || [];
if (this.checked) {
value.push(this.value);
}
break;
default:
value = this.value;
}
formData[name] = value;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment