Thomas Landauer
Thomas Landauer

Reputation: 8355

JavaScript: Make <select onchange> or <option onclick> keyboard-accessible

Similar questions have been asked before, but I'm looking for the "opposite" solution than all the others ;-)

I need a JavaScript event that fires when a user decides for an option in a select field.

What do I mean by decide:

Non-perfect solutions I've found so far:

The only solution I've found, having perfect accessibility, is ugly:

So (finally) my question is: Do you know any other way to achieve this without the submit button?

Upvotes: 4

Views: 1382

Answers (1)

Tigt
Tigt

Reputation: 1477

You could use the onInput event:

The DOM input event is fired synchronously when the value of an <input>, <select>, or <textarea> element is changed.

Right now, Firefox doesn’t support the event on <select> elements, but since onChange works like you want in Firefox, you can pick and choose. (You want an onChange listener for backwards compatibility, anyway.)

Upvotes: 2

Related Questions