Created
November 3, 2016 23:32
-
-
Save edavis25/269a7d264616a0307fe42c0bb7ab9f97 to your computer and use it in GitHub Desktop.
Javascript function for retrieving values from HTML select/option input.
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
/* | |
* Accept select box id (as string) and return the selected options as an array. | |
* @param {String} selectID HTML id for the select box. | |
*/ | |
function getSelectedOptions(selectID) | |
{ | |
var result = []; | |
var options = document.getElementById(selectID).options; | |
for (var i = 0; i < options.length; i++) | |
{ | |
if (options[i].selected) | |
{ | |
result.push(options[i].value); | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment