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

  • SEARCH
  • Home
  • 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 7875539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:59:56+00:00 2026-06-03T02:59:56+00:00

When I use the JQuery UI autocomplete, I need to have the tab key

  • 0

When I use the JQuery UI autocomplete, I need to have the tab key populate the search box with the first item in the autocomplete results, include a space afterwards, an then allow the user to continue typing.

<div class="ui-widget">
  <form id="searchbox" method="GET" action="http://duckduckgo.com/">
    <input id="search" type="text" name="q">
    <input id="submit" type="submit" value="Search">
  </form>
</div>
<script>
var tabKey = 9;
$('#search').autocomplete({
    source: [ 'this', 'that', 'foobar' ],
    delay: 0,
    selectFirst: true,
    select: function(event, ui) { if (event.keyCode == tabKey) { 
      $('#search').focus().select();
    } }
});
// without this, the tab key doesn't trigger an event                                                                                       
$('.ui-autocomplete').keypress(function(event) {});
</script>

In other words, in the example above, if someone typed “th”, they’d see “this” and “that” in the autocomplete choices. Hitting tab would add “this ” (note the space) to the input and focus would remain in the input.

Can someone give me a pointer as to what I’ve missed? I do not know Javascript very well, so small words are good 🙂

And perhaps more useful info (jquery 1.7.2) from the HEAD section:

<script src="js/jquery-latest.js"></script>
<script src="js/jquery-ui-1.8.20.custom.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/jquery-ui-1.8.20.custom.css" /> 

Edit: It appears that autoFocus: true will get me partway there. Now if I can just figure out how to keep focus on the input box.

  • 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-03T02:59:56+00:00Added an answer on June 3, 2026 at 2:59 am

    Hiya demo http://jsfiddle.net/DMDHC/

    Hope this helps, 🙂

    So if you type Ra you will see rambo and other options popping up and then hit tab key and you will see that added text + " " will appear with focus on the text box so that you can keep typing.

    Another thing I did is event.preventDefault(); which will prevent any default behavior, rest you know what you doing bruv! B-)

    jquery code

    $( "#search" ).autocomplete({
        source: function( req, resp ) {
            $.post( "/echo/json/", {
                json: '["Rambo", "Foobar", "This", "That", "Batman", "Hulk"]',
                delay: 1
            }, function(data) {
                resp( data );
            }, "JSON" );
        },
            select: function(event, ui) {
    
                 var TABKEY = 9;
                this.value = ui.item.value;
    
                if (event.keyCode == TABKEY) { 
                    event.preventDefault();
                    this.value = this.value + " ";
                    $('#search').focus();
                }
    
                return false;
            }
    });
    
    ​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to have an autocomplete functionality using jquery, and I've encountered ZendX_JQuery which
I'm attempting to use JQuery autocomplete and need to get the id of the
I am requesting youtube search terms for use with jquery autocomplete, but am having
I'm running a Rails 3 app, where I have a jQuery autocomplete box, which
I use jQuery UI autocomplete widget . Also I have GAE datastore: class Person(db.Model):
I use Jquery Autocomplete in my mvc3 application. I have a lot of textbox,
I use jquery.autocomplete , which uses a javascript regexp to highlight substrings in the
I am trying to use jquery autocomplete plugin, I want it to suggest ItemCodes
When I use JQuery's autocomplete and hardcode the array values in the page it
I'm trying to use JQuery's autocomplete plug-in but for some reasons Internet Explorer is

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.