Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7803567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:37:29+00:00 2026-06-02T01:37:29+00:00

I am making my own combobox for better design than a <select> tag. By

  • 0

I am making my own combobox for better design than a <select> tag.

By the way, I wish to know, how to make possible the navigation with the arrow keys of a keyboard between <span> (or other <p>…), and display the proposals with the “tab” key. Like the <option> of a <select> tag.

This is where I would like to make it work :

HTML

<input type="text" id="myInput" value=""/>
<div id="myDiv">
    <span>Value 1</span>    
    <span>Value 2</span>
    <span>Value 3</span>
</div>

​
CSS

#myDiv {display:none;border:1px solid #000;}
span  {display:block;background:#EDEDED;cursor:pointer;}
span:hover {background:#555;color:#FFF;}

JS

$(document).ready(function(){
    $('#myInput').focus(function(){
        $('#myDiv').slideDown();
    });    

    $('span').click(function(){
         $('#myInput').val($(this).html());
         $('#myDiv').slideUp();
    });
});​

You can test it here : http://jsfiddle.net/eHpKX/2/

Edit example : for example, click or tab in the input and then use the arrow keys to navigate… It doesn’t works.

Any help will be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T01:37:30+00:00Added an answer on June 2, 2026 at 1:37 am

    I wrote a keydown handler for uparrow and downarrow to act like select drop down. However tab key has a specific role in tabbing out to next field, So I didn’t want to prevtDefault browser behavior. See below code and you can build it more from there,

    DEMO

    CSS:

    span.active {background:#555;color:#FFF;}
    

    JS:

    $(document).ready(function() {
        $('#myInput').focus(function() {
            if ($('#myDiv span.active').length == 0) {
                $('#myDiv span:first').addClass('active');
            }
            $('#myDiv').slideDown();
        }).focusout(function() {
            $('#myDiv').slideUp();
        });
        $('span').click(function() {
            $('#myInput').val($(this).html());
        }).mouseenter(function() {
            $('#myDiv span').removeClass('active');
        }).keydown(function(e) {
            alert(e.which);
    
        });
    
        //keydown event
        $('#myInput').keydown(function(e) {
            var $actvOpt = $('#myDiv span.active');
            if (e.which == 13) { //enter key
                if ($actvOpt.length != 0) {
                    $(this).val($actvOpt.text());
                    $('#myDiv').slideUp();
                }
                return;
            }
    
            var actvIndex = $actvOpt.removeClass('active').index();
            var optCount = $('#myDiv span').length;
    
            if (e.which == 40) { //keydown
                actvIndex += 1;
            } else if (e.which == 38) { //keydown
                actvIndex -= 1;
            }
    
            if (actvIndex < 0) actvIndex = optCount - 1;
            else if (actvIndex >= optCount) actvIndex = 0;
    
            $('#myDiv span:eq(' + actvIndex + ')').addClass('active');
    
            $actvOpt = $('#myDiv span.active');
            $(this).val($actvOpt.text());        
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making my own WYSIWYG editor. But i can't make any text bold
I'm making my own minor mode for emacs. Now I want to add button
I'm making my own ControlTemplate for a standard Button in WPF. I want to
I'm making my own scheduler, which is going to be used in one of
I'm making my own website using html and php, and a database using mysql
i am making my own framework and would like to allow easy direct access
I am making my own installer and it's almost complete. The only thing lacking
All the current tutorials on making your own youtube video downloader are outdated. The
So, I'm making my own sequential loader. It has different functions for SWF, FLV
Ok, I attempted at making my own search function which doesnt work very well.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.