Skip to content

Instantly share code, notes, and snippets.

@mikemaccana
Created May 7, 2013 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikemaccana/5531683 to your computer and use it in GitHub Desktop.
Save mikemaccana/5531683 to your computer and use it in GitHub Desktop.
Vanilla JS: select an option in a select box by value
// Required for 7000+ option select box used in EC2 UI that has no search
NodeList.prototype.forEach = Array.prototype.forEach
var requiredValue = 'snap-d1d0a88a'
var selectBox = document.querySelector('select')
selectBox.childNodes.forEach(function(element, index){
if ( element.value === requiredValue ) {
console.log('Found! Index is ', index)
selectBox.selectedIndex = index
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment