Created
May 7, 2013 10:25
-
-
Save mikemaccana/5531683 to your computer and use it in GitHub Desktop.
Vanilla JS: select an option in a select box by value
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
// 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