[jQuery] Re: $(form).serialize() does not include submit button data

2010-01-04 Thread Milan Andric
Makes sense, that's also a simple workaround.  Thanks.

--
Milan


[jQuery] Re: $(form).serialize() does not include submit button data

2010-01-04 Thread coopster
Exactly.  jQuery doesn't know which  was clicked
by the time it gets around to the serialize method.  jQuery knows all
the form input types, but which submit button was clicked?  Which
input type image was clicked?  It is because of lines 3296 and 3297 of
the serialize function in jQuery.  Here are the two source code lines
and the complete methods are listed below for serialize() and
serializeArray() (serializeArray is called by serialize):


3296 (this.checked || /select|textarea/i.test(this.nodeName) ||
3297 /text|hidden|password|search/i.test(this.type));



serialize: function() {
return jQuery.param(this.serializeArray());
},
serializeArray: function() {
return this.map(function(){
return this.elements ? jQuery.makeArray(this.elements) 
: this;
})
.filter(function(){
return this.name && !this.disabled &&
(this.checked || 
/select|textarea/i.test(this.nodeName) ||

/text|hidden|password|search/i.test(this.type));
})
.map(function(i, elem){
var val = jQuery(this).val();
return val == null ? null :
jQuery.isArray(val) ?
jQuery.map( val, function(val, i){
return {name: elem.name, value: 
val};
}) :
{name: elem.name, value: val};
}).get();
}

It's not checking for input type submit elements.  However, you have
it right in your "click" event handler, so use this little workaround:

var post = $(this).attr("name") + "=" + $(this).val();
var data = $(this.form).serialize() + "&" + post;


[jQuery] Re: $(form).serialize() does not include submit button data

2010-01-03 Thread Dave Methvin
> I would think the submit button data would also be included when doing
> $(form_obj).serialize()?

When you submit a form manually, the value of the submit button
clicked is sent as part of the form. If you serialize the form using
Javascript, no button was clicked so none of them are serialized.