Created
September 4, 2012 16:54
-
-
Save CheapDevotion/3623406 to your computer and use it in GitHub Desktop.
Converts an html select list to a javascript object.
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
| var array = new Object(); | |
| $("#select option").each(function() { | |
| var optgroup = $(this).parent().attr("label"); | |
| if (optgroup != undefined) { | |
| if (array[optgroup] == undefined) { | |
| array[optgroup] = new Object(); | |
| } | |
| array[optgroup][$(this).val()] = $(this).text(); | |
| } | |
| else { | |
| array[$(this).val()] = $(this).text(); | |
| } | |
| }); | |
| console.log(JSON.stringify(array)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment