> For the complete documentation index, see [llms.txt](https://jscula.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jscula.gitbook.io/docs/form/.serialize.md).

# .serialize()

Serializes a form into a JavaScript object.

## serialize()

Serializes a form into a JavaScript object, capturing input values based on `name` attributes.

```html
<form id="myForm">
  <input type="text" name="username" value="JohnDoe">
  <input type="email" name="email" value="john@example.com">
  <input type="radio" name="gender" value="male" checked>
  <input type="radio" name="gender" value="female">
  <select name="country">
    <option value="US" selected>United States</option>
    <option value="CA">Canada</option>
  </select>
  <button type="submit">Submit</button>
</form>
```

#### Usage:

```javascript
const formData = $('#myForm').serialize();
console.log(formData);
/* Output:
{
  username: "JohnDoe",
  email: "john@example.com",
  gender: "male",
  country: "US"
}
*/
```
