Created
September 22, 2016 14:29
-
-
Save marcusshepp/09caf5e03a254c488592b96ffc4e65f0 to your computer and use it in GitHub Desktop.
Get selected values from a select element with multiple = 'multiple'
This file contains 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
function get_selected_values(select_element){ | |
/* | |
Vanilla JS way of returning an array of selected elements from a | |
select element with multiple='mulitple'. | |
Used to allow for multiple Evaluation Categories to be | |
selected. | |
*/ | |
var result = []; | |
var options = select_element && select_element.options; | |
var opt; | |
for (var i = 0, i_len = options.length; i < i_len; i++){ | |
opt = options[i]; | |
if (opt.selected){ | |
result.push(opt.value || opt.text); | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment