- $("input,textarea,option",this).filter(":enabled").each(function(){
- // Skip selects with options which are not selected
- if ((this.parentNode.type == 'select-one' || this.parentNode.type == 'select-multiple') && !this.selected) {
- return null;
- }
-
- // Skip radio and checkbox elements which are not checked
- if ((this.type == 'radio' || this.type == 'checkbox') && !this.checked) {
- return null;
- }
+ var ok = {INPUT:true, TEXTAREA:true, OPTION:true};
+
+ // Loop the shite
+ $('*', this).each(function() {
+ // Skip elements not of the types in ok
+ if (!ok[this.tagName.toUpperCase()])
+ return;
+
+ // Skip disabled elements
+ if (this.disabled)
+ return;
+
+ // Skip submit buttons and image elements
+ if ((this.type == 'submit') || (this.type == 'image'))
+ return;
+
+ // Skip non-selected options
+ var oParent = this.parentNode;
+ var sNn = oParent.nodeName.toUpperCase();
+ if (((sNn == 'SELECT') || (sNn == 'OPTGROUP')) && (!this.selected))
+ return;
+
+ // Skip non-checked nodes
+ if (((this.type == 'radio') || (this.type == 'checkbox')) && (!this.checked))
+ return;
+
+ // If we come here, everything is fine
+ var sKey = this.name || this.id || oParent.name || oParent.id;
+ var sValue = this.value;
+
+ // If we don't have an ID, and the parent is an OPTGROUP,
+ // get the NAME or ID of the OPTGROUP's parent
+ if ((!sKey) && (sNn == 'OPTGROUP') && (oParent = oParent.parentNode))
+ sKey = oParent.name || oParent.id;
+
+ // Add the data
+ a.push({ name: sKey, value: sValue });
+ });