Buttle Butkus
Buttle Butkus

Reputation: 9486

Use up/down arrows to scroll select list but keep focus on input element

I want user to be able to scroll through select options with up/down arrows, but be able to press ctrl-c to copy from a matching input element whenever they want, seamlessly.

But I'm having trouble juggling the focus.

The best I've gotten is it works but I have to press down twice to move to the next select element.

Here is a fiddle I created, which isn't even populating the select box for some reason. Though it works on my server. On my server the picsarray array is generated with PHP, but it should be the same effect as here.

https://jsfiddle.net/bbmqy0xm/2/

Upvotes: 0

Views: 892

Answers (1)

Malk
Malk

Reputation: 11993

You can leave focus alone and just call select() to highlight the text after you set it:

function showpicture(selectobj) {
    /* deleted irrelevant js */
    $("#image_name").val($(selectobj).val()).select();  
}

https://jsfiddle.net/s4rmytt5/

Upvotes: 1

Related Questions