Created
March 12, 2017 10:22
-
-
Save Dosant/0552614e621588511ccf83ab75c66f8d to your computer and use it in GitHub Desktop.
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="tags-select" multiple> | |
<option value="политика" selected>Политика</option> | |
<option value="музыка" selected>Музыка</option> | |
<option value="спорт">Спорт</option> | |
</select> | |
<p id="tags-text"><p> |
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
var tagsSelect = document.getElementById('tags-select'); | |
var tagsText = document.getElementById('tags-text'); | |
function handleTagsChange() { | |
var options = [].slice.call(tagsSelect.options); | |
var selectedOptionsString = options | |
.filter(function (option) { | |
return option.selected; | |
}) | |
.map(function (option) { | |
return option.value; | |
}) | |
.join(', '); | |
tagsText.textContent = selectedOptionsString; | |
} | |
tagsSelect.addEventListener('change', handleTagsChange); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment