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 8062799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:47:45+00:00 2026-06-05T10:47:45+00:00

I have an input box that uses jQuery autocomplete. I’d like to add a

  • 0

I have an input box that uses jQuery autocomplete. I’d like to add a little functionality to the page so it can accept a value on page load and then select the top choice in the autocomplete list. I’ve created a jsfiddle to demonstrate what I mean:

http://jsfiddle.net/bwhitney/MQpQG/2/

Or here is just the code:

var myArray = ["apple - a ripe red fruit"
, "banana - yellow fruit grown in bunches"
, "orange - the name says it all"];

$("input#textbox").autocomplete({
    source: myArray
});

$('#clickme').click(function() {
    // select the #1 autocomplete option for the given text "apple"
    // ???
});​

With the html:

<input type="text" id="textbox" />
<input type="button" id="clickme" value="Set the value" />

So for example if the page loaded with the value “apple” then the text “apple – a ripe red fruit” should be loaded. Sending the entire phrase “apple – a ripe red fruit” is not a viable option in this case.

I could write a loop that iterates over each item in the array and parses out the first word, but I’m hoping jQuery has a better way of doing it since it can already get the correct answer at the top of its list.

Edit: Just to clarify, I figured if I can get it to work by pressing a button I can also get it to work by passing in a value when the page loads. That’s why my example uses a button instead of on page load.

  • 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-05T10:47:48+00:00Added an answer on June 5, 2026 at 10:47 am

    It’s not much effort to write it yourself, and no matter how you look at it, you’re going to have to iterate over the array to find the item you’re looking for.

    var myWord = "apple";
    
    $('#clickme').click(function() {
        for (item in myArray) {
            if (myArray[item].indexOf(myWord) == 0)
                $("#textbox").val(myArray[item]);
        }
    });
    

    Demo

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page that uses jQuery to create a number of <input> DOM
In my ASP.NET page, I have an input box that has to have the
I have a jQuery autocomplete input box for time. It lists all available times
I Have a function that references a specific input text box. I would like
I have a search box that uses jQuery to submit the user's search and
I have jQuery that uses the change event from a selection box to update
I have a search box on my site that uses autocomplete to give suggestions,
I have a page with an input box, and a function that processes the
I have an input box that successfully toggles a hidden div. However, I also
I have an input box that takes values from 0-100. I want to prevent

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.