Skip to content

Instantly share code, notes, and snippets.

@Dosant
Created March 12, 2017 10:22
Show Gist options
  • Save Dosant/0552614e621588511ccf83ab75c66f8d to your computer and use it in GitHub Desktop.
Save Dosant/0552614e621588511ccf83ab75c66f8d to your computer and use it in GitHub Desktop.
<select id="tags-select" multiple>
<option value="политика" selected>Политика</option>
<option value="музыка" selected>Музыка</option>
<option value="спорт">Спорт</option>
</select>
<p id="tags-text"><p>
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