Search code examples
jqueryquery-stringform-fieldsauto-populatingform-processing

jQuery - can I fill form inputs from a serialized form string?


Given that I have some form on a page, I know I can get a unicode serialized string using

var query = jQuery('#some-form').serialize();

It's also possible setting the value of each input with $('#some-input').val(...). Assuming that same form above was reset, but I still have the query string - is there a simple way to populate the form from that string? I realize I could parse it and set every input/select individually, but I was looking for a simpler solution. Thanks.


Solution

  • You could serialize the form into a JSON array and use an MVVM mapping plugin like Knockout.js to auto-fill the form.

    See Serializing to JSON in jQuery