I have a multi-select list box. I want to be able to select a number of items and act on the selection by pressing the Enter key. The problem I’m having is that when I press Enter the current item at the cursor becomes the only item selected. The others are deselected so my function only acts on a single item.
What can I do to prevent the Enter key from selecting an item?
I am setting up the onkeypress function in JavaScript as follows. The doListKeyPress checks for the Enter key and acts on it.
select.onkeypress = function(e) { doListKeyPress(e, "myListName"); };
Add this event:
As
keydowncomes beforekeypress, it will set the focus away from the listbox hence the default browserEnterbehavior is ‘bypassed’.Disclaimer:
This answer does not allow selection of item by Enter. It can be done with further implementation though.