Skip to content
Advertisement

Tag: html-select

Getting selected options with querySelectorAll

I wonder if it’s possible in Javascript to get the currently selected options in a <select multiple> field using the Selctors API rather than a “stupid” iteration over all options. select.querySelectorAll(‘option[selected=”selected”]’) only returns the options that were marked as preselected in the original HTML, which is not what I’m looking for. Any ideas? Answer document.querySelectorAll(‘option:checked’) Works even on IE9 😉

Capture events in list

I would like to know how to capture events within the dropdown list when a user click on a “select” dropdown list. I would like for example to intercept events when different elements of list are on focus. I tried to tie event listeners to the option elements of the list but they do not capture anything. See sample code

JavaScript, oninput change innerHTML of option tag

i need to change the innerHTML text of a option tag, based on the input of an input form. I did it like this but as soon as i write “1” it gets locked up and i cannot write anything else there. It does change the text but it doesn’t allow you to write anything else, or change from 1

Advertisement