Selecting an item in an HTML SELECT list using the keyboard does not raise a CLICK event

I have an HTML select list that, when an element is selected, should show other information below it. Onclick or jQuery change events are fired when a selection list item is selected by clicking with the mouse (mouse), but not when the user uses keystrokes (keyboard).

Any idea which event you need to look to determine when the selected list item has changed?

Here is a BASIC example:

<select id="mylist" name="mylist">
    <option value="">(none)</option>
    <option value="1">Test 1</option>
    <option value="2">Test 2</option>
    <option value="3">Test 3</option>
</select>

<span id="myspan"></span>

<script type="text/javascript">
    $("#mylist").change(function() {
        $("#myspan").html($("#mylist").attr("selectedIndex"));
    });
</script>
+3
source share
3 answers

, select
( select)

+2

OnChange .

, IE , Firefox, , enter, . , <select> (OnBlur - OnChange ), .

, ...

+1

, add:

multiple="multiple"

dropbox, keyup document.body - .

0
source

Source: https://habr.com/ru/post/1742102/


All Articles