Created
August 20, 2012 15:52
-
-
Save cam-gists/3405320 to your computer and use it in GitHub Desktop.
JQuery: Form Serialization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $('.btn').click(function(){ | |
| var inputs = $('[type=text]'); | |
| var pw = $('[type=password]'); | |
| var checkboxes = $('[type=checkbox]:checked'); | |
| var selects = $('option:selected'); | |
| // next translate that into an array of just the values | |
| var password = $.map(pw, function(elt, i) { | |
| return $(elt).val(); | |
| }); | |
| var sels = $.map(selects, function(elt, i) { | |
| return $(elt).val(); | |
| }); | |
| var inps = $.map(inputs, function(elt, i) { | |
| return $(elt).val(); | |
| }); | |
| var checks = $.map(checkboxes, function(elt, i) { | |
| return $(elt).val(); | |
| }); | |
| console.log("SELECTS : " + sels); | |
| console.log("INPUTS : " + inps); | |
| console.log("CHECKS : " + checks); | |
| console.log("PW : " + password); | |
| }); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment