view raw
Akshat Akshat - 7 months ago 70
jQuery Question

JQuery serializeArray key value pairs

I'm having a bit of trouble serializing a form

<input type="text" name="name1" value="value1"/>
<input type="text" name="name2" value="value2"/>


Will return

Is it possible to get output in the form


So that they are easier to handle?

var result = { };
$.each(​$('form')​.serializeArray()​, function() {
    result[] = this.value;

// at this stage the result object will look as expected so you could use it
alert('name1 = ' + result.name1 + ', name2 = ' + result.name2);

Live demo.