Skip to content

Instantly share code, notes, and snippets.

@iddar
Last active December 31, 2015 04:29
Show Gist options
  • Select an option

  • Save iddar/7935001 to your computer and use it in GitHub Desktop.

Select an option

Save iddar/7935001 to your computer and use it in GitHub Desktop.
serializeForm es una funcion para serealisar un form para pasarlo por GET, regresa el urlstring. Esta es una funcion amplida de: http://onwebdev.blogspot.com/2011/05/serializing-form-without-jquery.html a la cual le agrege los nuevos typos de html5
function serializeForm(form) {
form = document.getElementById(form) || document.forms[0];
var elems = form.elements;
var serialized = [], i, len = elems.length, str='';
for(i = 0; i < len; i += 1) {
var element = elems[i];
var type = element.type;
var name = element.name;
var value = element.value;
switch(type) {
case 'color':
case 'date':
case 'datetime':
case 'datetime-local':
case 'email':
case 'month':
case 'number':
case 'range':
case 'search':
case 'tel':
case 'time':
case 'url':
case 'week':
case 'text':
case 'radio':
case 'tel':
case 'checkbox':
case 'textarea':
case 'select-one':
str = name + '=' + value;
serialized.push(str);
break;
default:
break;
}
}
return serialized.join('&');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment