Created
July 8, 2013 01:18
-
-
Save gmilby/5945612 to your computer and use it in GitHub Desktop.
use jquery & .each( to get values of selected items in a pulldown
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
$('#select > option').each(function() { | |
alert($(this).text() + ' ' + $(this).val()); | |
}); | |
$('#select > option:selected').each(function() { | |
alert($(this).text() + ' ' + $(this).val()); | |
}); | |
// This function will return an array of text/value pairs for the selects matching the given class. | |
function getSelects(klass) { | |
var selected = []; | |
$('select.' + klass).children('option:selected').each( function() { | |
var $this = $(this); | |
selected.push( { text: $this.text(), value: $this.val() ); | |
}); | |
return selected; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment