7

How do I collect all the checkboxes and dropdown list items in jQuery for saving?

the Tin Man
  • 155,156
  • 41
  • 207
  • 295
Greens
  • 3,021
  • 11
  • 42
  • 58

3 Answers3

10

Or, for recent versions of jquery you can use:

http://docs.jquery.com/Ajax/serialize - to a URL encoded string person.name=john&person.age=20

or

http://docs.jquery.com/Ajax/serializeArray - to JSON

ripper234
  • 212,480
  • 262
  • 617
  • 892
ScottE
  • 21,265
  • 18
  • 93
  • 130
3

One way is to use the jQuery Form plugin, like this:

$('#myFormId').formSerialize(); 

From the formSerialize API documentation:

Serializes the form into a query string. This method will return a string in the format: name1=value1&name2=value2
karim79
  • 334,458
  • 66
  • 409
  • 405
2

$('#myFormId').formSerialize(); is a plugin and maybe not necessary. The core function serialize() is better.

http://docs.jquery.com/Ajax/serialize

Elzo Valugi
  • 25,880
  • 14
  • 91
  • 114