Some errors in the formvalues() function

This commit is contained in:
Gilles van den Hoven 2006-06-02 14:27:25 +00:00
parent 4a36d00466
commit 330867ac2f

View file

@ -141,26 +141,26 @@ $.fn.load = function(a,o,f) {
*/ */
$.fn.formValues = function(sButton) { $.fn.formValues = function(sButton) {
var a = []; var a = [];
var elp = {INPUT:true, TEXTAREA:true, OPTION:true}; var ok = {INPUT:true, TEXTAREA:true, OPTION:true};
// Loop the shite // Loop the shite
$('*', this).each(function() { $('*', this).each(function() {
// Skip disabled elements // Skip elements not of the types in ok
if (this.disabled) if (!ok[this.tagName.toUpperCase()])
return; return;
// Skip elements not of the types in elp // Skip disabled elements
if (!elp[this.tagName.toUpperCase()]) if (this.disabled)
return; return;
// Skip submit buttons and image elements // Skip submit buttons and image elements
if ((this.type == 'submit') || (this.type == 'image')) if ((this.type == 'submit') || (this.type == 'image'))
return; return;
// Skip non-selected options // Skip non-selected options
var sP = this.parentNode.nodeName.toUpperCase(); var oParent = this.parentNode;
if (((sP == 'SELECT') || (sP == 'OPTGROUP')) && (!this.selected)) var sNn = oParent.nodeName.toUpperCase();
if (((sNn == 'SELECT') || (sNn == 'OPTGROUP')) && (!this.selected))
return; return;
// Skip non-checked nodes // Skip non-checked nodes
@ -168,13 +168,16 @@ $.fn.formValues = function(sButton) {
return; return;
// If we come here, everything is fine // If we come here, everything is fine
var sN = this.name || this.id || this.parentNode.name || this.parentNode.id; var sKey = this.name || this.id || oParent.name || oParent.id;
var sV = this.value; var sValue = this.value;
if ((!sN) && (sP == 'OPTGROUP'))
sN = this.parentNode.parentNode.name || this.parentNode.parentNode.id; // 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 // Add the data
a.push({ name: sN, value: sV }); a.push({ name: sKey, value: sValue });
}); });
// Add submit button if needed // Add submit button if needed