I found earlier discussion about select multiple serizlization
question at http://jquery.com/discuss/2006-September/010887/ . And I
also encounter the same problem again. I used a multiple select, but
the select.val() will only return one value but not the multiple
values. So I checked the param() function, and it didn't think about
select-multiple also, and the param() can receive two type of
parameter, one you could pass it a jQuery object, the other you could
pass is a hash object. But it don't think about I perhaps serializing
the data myself, so I may pass it a string object. So I have two
question:

1. Why not enable the param receive string parameter?
2. Don't consider select-mulitple

So I think the param() function is not very handy, because you should
select the element in the outer, for example, you sould do like this:

$(''[EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED]').serialize()

And it has the problem 2.

So I write a serialize() method:

$.fn.serialize = function(){
    var s = [];
    $('[EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED]', 
this).each(function (){
        if(this.disabled || (this.type == 'checkbox' || this.type ==
'radio') && !this.checked)
            return;
        if (this.type == 'select-multiple'){
            var name = this.name;
            $('option:selected', this).each(function(){
                s.push(name + '=' + this.value);
            });
        }
        else
            s.push(this.name + '=' + this.value);
    });
    return s.join('&');
}

And I also  change the param() method, add some code at the top of the function:

        if (a.constructor == String)
            return a;

So that the param() can receive a string obj, and just return it.

-- 
I like python!
UliPad <<The Good Python Editor>>: http://wiki.woodpecker.org.cn/moin/UliPad
My Blog: http://www.donews.net/limodou

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to