Skip to content

Instantly share code, notes, and snippets.

@edavis25
Created November 3, 2016 23:32
Show Gist options
  • Save edavis25/269a7d264616a0307fe42c0bb7ab9f97 to your computer and use it in GitHub Desktop.
Save edavis25/269a7d264616a0307fe42c0bb7ab9f97 to your computer and use it in GitHub Desktop.
Javascript function for retrieving values from HTML select/option input.
/*
* 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