Skip to content

Instantly share code, notes, and snippets.

@gmilby
Created July 8, 2013 01:18
Show Gist options
  • Save gmilby/5945612 to your computer and use it in GitHub Desktop.
Save gmilby/5945612 to your computer and use it in GitHub Desktop.
use jquery & .each( to get values of selected items in a pulldown
$('#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