7

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

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Greens
  • 3,061
  • 11
  • 43
  • 61

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
  • 222,824
  • 274
  • 634
  • 905
ScottE
  • 21,530
  • 18
  • 94
  • 131
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
  • 339,989
  • 67
  • 413
  • 406
2

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

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

Elzo Valugi
  • 27,240
  • 15
  • 95
  • 114