serialize
/* jQuery.values: get or set all of the name/value pairs from child input controls
* @argument data {array} If included, will populate all child controls.
* @returns element if data was provided, or array of values if not
*/
$.fn.values = function(data) {
var els = $(this).find(':input').get();
if(typeof data != 'object') {
// return all data
data = {};
$.each(els, function() {
if (this.name && !this.disabled && (this.checked
|| /select|textarea/i.test(this.nodeName)
|| /text|hidden|password/i.test(this.type))) {
data[this.name] = $(this).val();
}
});
return data;
} else {
$.each(els, function() {
if (this.name && data[this.name]) {
if(this.type == 'checkbox' || this.type == 'radio') {
$(this).attr("checked", (data[this.name] == $(this).val()));
} else {
$(this).val(data[this.name]);
}
}
});
return $(this);
}
};