Created
January 23, 2014 17:01
-
-
Save Daniel-Wiedemann/0c668fef95032029ab41 to your computer and use it in GitHub Desktop.
Get value and label from select HTMLElement
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
// <select id="test1"> | |
// <option value="1">a</option> | |
// <option value="2">b</option> | |
// <option value="3">c</option> | |
// </select> | |
document.getElementById('test1').addEventListener('change', function(event){ | |
var that = this; // or event.target | |
// if option has no value attribute, the event value returns the label | |
console.log('value: ' + that.value + ' | label: ' + that.selectedOptions[0].label); | |
// if first is selected it will return | |
// "value: 1 | label: a" | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment