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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:06:02+00:00 2026-05-20T05:06:02+00:00

am new to jquery! I’m using jquery ui autocomplete in my application where the

  • 0

am new to jquery! I’m using jquery ui autocomplete in my application where the auto complete values comes from database. Here are codes that am using but nothing happens

search.php

<?php

    $conn = mysql_connect("localhost", "root", "");
    mysql_select_db("webforum", $conn);

    $q = strtolower($_GET["term"]);

    $query = mysql_query("select name from groups where name like %$q%");
    while ($row = mysql_fetch_array($query)) {
        echo json_encode($row);
    }
    ?>

Here is test.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta  charset="utf-8">
    <title> jQuery UI Autocomplete - Multiple, remote </title>
    <link rel="stylesheet" href="theme/jquery.ui.all.css">
        <script type="text/javascript" src="jquery/jquery-1.4.4.min.js"></script>
    <script type="text/javascript" src="jquery/ui/jquery.ui.core.js"></script>
    <script type="text/javascript" src="jquery/ui/jquery.ui.widget.js"></script>
    <script type="text/javascript" src="jquery/ui/jquery.ui.position.js"></script>
    <script type="text/javascript" src="jquery/ui/jquery.ui.autocomplete.js"></script>
        <style type="text/css">
    .ui-autocomplete-loading { background: white url('images/ui-anim_basic_16x16.gif') right center no-repeat; }
    </style>
        <script type="text/javascript">
    $(function() {
        function split( val ) {
            return val.split( /,\s*/ );
        }
        function extractLast( term ) {
            return split( term ).pop();
        }

        $( "#birds" )
            // don't navigate away from the field on tab when selecting an item
            .bind( "keydown", function( event ) {
                if ( event.keyCode === $.ui.keyCode.TAB &&
                        $( this ).data( "autocomplete" ).menu.active ) {
                    event.preventDefault();
                }
            })
            .autocomplete({
                source: function( request, response ) {
                    $.getJSON( "http://localhost/webforum/search.php", {
                        term: extractLast( request.term )
                    }, response );
                },
                search: function() {
                    // custom minLength
                    var term = extractLast( this.value );
                    if ( term.length < 2 ) {
                        return false;
                    }
                },
                focus: function() {
                    // prevent value inserted on focus
                    return false;
                },
                select: function( event, ui ) {
                    var terms = split( this.value );
                    // remove the current input
                    terms.pop();
                    // add the selected item
                    terms.push( ui.item.value );
                    // add placeholder to get the comma-and-space at the end
                    terms.push( "" );
                    this.value = terms.join( ", " );
                    return false;
                }
            });
    });
    </script>
</head>
<body>

<div class="demo">

<div class="ui-widget">
    <label for="birds">Birds: </label>
    <input id="birds" size="50" />
</div>

</div>
</body>
</html>

Can anyone help me with this?
Thanx in Advance!

  • 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-05-20T05:06:02+00:00Added an answer on May 20, 2026 at 5:06 am

    How does your json looks like?
    in order to work wit jquery-ui autocomplete you need to have at least label and value properties:

    {
       'label' : 'your_label',
       'value' : 'your_value'
    }
    

    in your js code you are asking for value property which doesn’t seem to bes set on your json produced by php.

    here is a similar question: Having problems with jQuery UI Autocomplete

    so php has to build the results in the right way:

        $conn = mysql_connect("localhost", "root", "");
        mysql_select_db("webforum", $conn);
    
        $q = strtolower($_GET["term"]);
    
       $return = array();
    
        $query = mysql_query("select name from groups where name like %$q%");
        while ($row = mysql_fetch_array($query))
        {
            //since we have just 1 value from the db just use it as both value and label
            array_push($return,array('label'=>$row['name'],'value'=>$row['name']));
        }
    
       echo(json_encode($return));
    

    P.S. it is not that safe make queries with $_GET[] parameters.

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

Sidebar

Related Questions

New to jQuery, I have a script that returns data from an XML file.
Ok, I am new to JQuery, I have a modal that has a asp:Literal
New to javascript/jquery and having a hard time with using this or $(this) to
I am relatively new to using jQuery and would like to use the load
The new jQuery v1.4 says this... jQuery.ajax() is now using onreadystatechange instead of a
When writing a new jQuery plugin is there a straightforward way of checking that
Using jQuery UI 1.8rc3 combined with the new jquery.effects.fade.js code, I've been able to
I am using this new jQuery plugin called jsTree www.jstree.com and using the HTML
What's the easiest way to define a new jQuery member function ? So that
I am brand new to Jquery and have run into something that if answered

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.