Is it possible to find out which select option has focus in IE before it is selected?

482 Views Asked by At

I'm trying to enable custom keyboard navigation of a jqxGrid. I've got it working 99.9% of the way, but I can't get IE to select the highlighted/focused options in a select box.

I wanted to see if there was a way to detect the option that's being focused on in order to manually set the select value when I hit the enter key.

I've tried:

var optVal = $select.find('option:selected').val();
$select.val(optVal);

which just gets the previous val of the select element, and:

var optVal = $select.find('option:focus').val();
$select.val(optVal);

which gets nothing.


EDIT: Also, I can't bind events directly to my controls.

1

There are 1 best solutions below

1
On

How about checking the target.event of the keyup event (try on the select or on the option) ?

$("myselect").keyup(function(e) {
    var code = e.which;
    if(code==13) {
        //check the event.target
    }
});

$("myselect option").keyup(function(e) {
    var code = e.which;
    if(code==13) {
        $("myselect").val($(this).val());
    }
});