function getFormHash (formSelector)
{
hash = {};
inputs = {};
jQuery (formSelector + 'input'). each (function () {
name = jQuery (this) .attr ('name');
value = jQuery (this) .attr ('value');
type = jQuery (this) .attr ('type');
if (name.substr (name.length-2, 2) == '[]]) {
name = name.substr (0, name.length-2)
if (typeof (inputs [name]) == 'undefined') {
inputs [name] = 0;
}
else {
inputs [name] ++;
}
if (type.toUpperCase ()! = 'CHECKBOX' || jQuery (this) .attr ('checked') == true) {
hash [name + '[' + inputs [name] + ']'] = value;
}
}
else {
hash [name] = value;
}
});
jQuery (formSelector + 'select'). each (function () {n
name = jQuery (this) .attr ('name');
multiple = jQuery (this) .attr ('multiple');
if (typeof (name)! == 'undefined') {
i = 0;
jQuery (this) .children ('option'). each (function () {
if (jQuery (this) .attr ('selected')) {
value = jQuery (this) .attr ('value');
if (multiple == true)
hash [name + '[' + i + ']'] = value;
else
hash [name] = value;
i ++;
}
});
}
});
jQuery (formSelector + 'textarea'). each (function () {
name = jQuery (this) .attr ('name');
value = jQuery (this) .html ();
hash [name] = value;
});
return hash;
} Source: https://habr.com/ru/post/43042/
All Articles