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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:17:23+00:00 2026-06-15T10:17:23+00:00

I am trying to use AJAX to auto complete the users text. Right now

  • 0

I am trying to use AJAX to auto complete the users text. Right now I got AJAX to return the results I need for the auto complete feature to the ‘suggestions’ div as the user types. However, what I am trying to accomplish is a dropdown coming out of the input field (“prod-name”) with suggestions as options where the user can simply click on their preferred suggestion and make it the ‘value’ of the input (similar to how google has search suggestions as you type, but a simplified version).

My markup sof far:

<script type="text/javascript">
    function search(searchword) {
      $('#suggestion').load('invoice-get-data.php?searchword=' + searchword);
    }
</script>
</head>
<body>

<div class="prod-name">
    <input onKeyPress="search(this.value)" type="text" id="prod-name"/>
    <div id="suggestion"></div>
</div>
</body>

My AJAX code so far (invoice-get-data.php code snippet)

$searchword = $_GET['searchword'];

    $results = mysql_query("SELECT * FROM products WHERE prod_name LIKE '".$searchword."%'") or die(mysql_error());

    while($row = mysql_fetch_array($results)){
        echo $row['prod-name'] . '<br>';
    }   
  • 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-15T10:17:24+00:00Added an answer on June 15, 2026 at 10:17 am

    jquery ui provides a widget for such autocompletion : http://jqueryui.com/autocomplete/ .

    The javascript side would be:

    <script>
    $(function() {
        $( "#prod-name" ).autocomplete({
            source: "invoice-get-data.php",
            minLength: 2,
            select: function( event, ui ) {
                alert("Product #" + ui.item.id + " selected");
                return true;
            }
        }
        });
    });
    </script>
    

    And the PHP side would be:

    $searchword = $_GET['term'];
    
    $results = mysql_query("SELECT * FROM products WHERE prod_name LIKE '".$searchword."%'") or die(mysql_error());
    
    $data = array();
    while($row = mysql_fetch_array($results)){
        $data[]     = array(
            "id"        => $row['id'],
            "value"     => $row['prod-name'],
            "label"     => $row['prod-name']
        );
    }   
    
    echo json_encode($data);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to add auto complete functionality to a text box. I want
I'm trying to use the jquery ui autocomplete feature with an ajax datasource and
I am trying to use ajax to update the views which simply checking results
I'm trying to use jquery autocomplete on a text field to allow users to
I'm trying to use an auto-complete widget that gets its data from a remote
I am trying to use AJAX for a web app game that im making.
I am currently trying to use AJAX in my application via jRails. I am
I am trying to use .ajax() to post a People object to a MVC2
I'm trying to use jquery.Ajax to post data to an ASP.NET MVC2 action method
I am using HMVC codeigniter. I am trying to use jquery ajax first time.

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.