Skip to content

Instantly share code, notes, and snippets.

@subtleGradient
Created October 16, 2008 01:29
Show Gist options
  • Select an option

  • Save subtleGradient/17048 to your computer and use it in GitHub Desktop.

Select an option

Save subtleGradient/17048 to your computer and use it in GitHub Desktop.
// TODO: Remove this once it's added to MooTools code
Element.implement({
toFormHash: function(){
var formHash = $H();
this.getElements('input, select, textarea', true).each(function(el){
if (!el.name || el.disabled) return;
var value = (el.tagName.toLowerCase() == 'select') ? Element.getSelected(el).map(function(opt){
return opt.value;
}) : ((el.type == 'radio' || el.type == 'checkbox') && !el.checked) ? null : el.value;
$splat(value).each(function(val){
if (typeof val != 'undefined')
formHash.set(el.name, val);
});
});
return formHash;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment