user1386320
user1386320

Reputation:

How to select an option from Select box using arrow keys?

I have tried with .change() and/or with .select(), even with .click(), but no hope.

When I stop on a select box field with a Tab-focus, and when I press up or down I'd like that currently focused option item to be selected instantly.

Is it possible to achive this with jQuery/JavaScript?

Upvotes: 1

Views: 1538

Answers (1)

user1386320
user1386320

Reputation:

This was more easy than I tought, with jQuery of course:

$('#year').on('keyup', function() {
    $(this).change();
});

As Xander suggested, I just triggered the .on('keyup') event on top of the select box field, and on each change of the selected value of the select box it will automatically select it and I have the event working!

Thanks all others who helped.

Upvotes: 1

Related Questions