I can figure out how to loop through input and select. My function below does not include select lists.
Any help welcome.
$('input', '#consumer_form').each(function(ke开发者_如何学Goy, value)
{
if ((this.type === "radio" || this.type === "checkbox") && this.checked === false) {
return;
} else {
val = this.value;
}
//alert($('#'+this.id).attr('name')+'='+replaceAmp(val));
formData += '&'+this.name+'='+replaceAmp(val);
});
Thanks
I believe it's $(":input") you're need if you want to loop through all the elements in the form http://api.jquery.com/input-selector/ (you don't have a colon there).
With jQuery you can get all input
and select elements
by doing this:
$('input, select')
So you would need to do something like
$('input, select').each(function(key, value) {
if ($(this).is('select')) do_select_stuff();
else if ($(this).is(':checkbox')) do_checkbox_stuff();
else if ($(this).is(':radio')) do_radio_stuff();
});
Try
$('input, select', '#consumer_form').each(function(key, value)
精彩评论