• page

jQuery.formParams jQuery.formParams

 

jQuery(el).formParams([convert])

jQuery.formParams adds jQuery.fn.formParams(convert) which serializes a form into a JavaScript object. It creates nested objects by using bracket notation in the form element name.

Parameters

  1. convert=false {Boolean}Optional

    If convert is true, values that look like numbers or booleans will be converted and empty strings won't be added to the object. For a form like this:

    <form>
      <input type="text" name="first" value="John" />
      <input type="text" name="last" value="Doe" />
      <input type="text" name="phone[mobile]" value="1234567890" />
      <input type="text" name="phone[home]" value="0987654321" />
    </form>
    

Returns

{Object}

returns an object with the form's element names and values:

$('form').formParams()
// -> {
//   first : "John", last : "Doe",
//   phone : { mobile : "1234567890", home : "0987654321" }
// }

jQuery(el).formParams(values)

Parameters

  1. values {Object}

    It is also possible to set form values by passing an object:

    $('form').formParams({
      first : 'Mike',
      last : 'Smith'
    });
    

    Demo