RubyRedGrapefruit
RubyRedGrapefruit

Reputation: 12224

How can I add something to serialized form values using jQuery?

I can not figure out the syntax for this.

Here's my code:

$('select[id^="lookup_"]').change(function() {
    var d = $("#lookupform").serializeArray();

            // This is the problem line
            d.push("field=" + $(this).id);

    hash = { type: "POST", url: "/map/details", data: d };
    $.ajax(hash);
    return false;
});

I know that problem line is totally wrong. I basically want to let the server side know from which the submission came from. Can anyone help?

Upvotes: 2

Views: 485

Answers (2)

Jacek Kaniuk
Jacek Kaniuk

Reputation: 5229

this should do:

d.push( { field: this.id } );

Upvotes: 1

Matt Ball
Matt Ball

Reputation: 359816

You're very, very close. This will work:

d.push("field=" + this.id);

Or, to be consistent with the other array elements:

d.push({field: this.id});

Upvotes: 1

Related Questions