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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:42:23+00:00 2026-05-27T22:42:23+00:00

I have a search box in my application that uses the jQuery UI Autocomplete

  • 0

I have a search box in my application that uses the jQuery UI Autocomplete plugin to display a list of users in the system based on last name, from a remote data source.

When a user is clicked from the autocomplete list, I’d like the browser to redirect to that user’s individual page (based on a GET parameter). However, the GET parameter for the user page is the user “id”, different from the display values “last_name, first_name”.

How do I push the user “id” to the GET parameter while still displaying the first and last names values in the dropdown?

I have seen similar questions asked on here, but none while using a remote data source.

Any help you can provide, would be amazing!

Javascript:

$(document).ready(function() {

    $( ".user_autocomplete" ).autocomplete({
            source: "../../db/users.php",
            minLength: 0,
            focus: function (event, ui) {
                this.value = ui.item.value;
            },          
    }).bind( "autocompleteselect", function(event, ui) {
        window.location.href = "/users/index.php?id=" + this.value;
    });

});  

Remote Data Source (users.php)

<?php

$return_arr = array();

if(isset($_GET['term'])) {
    $mysearchString = $_GET['term'];
}

$sth = $dbh->query("SELECT id, first_name, last_name FROM users
                    WHERE last_name LIKE '$mysearchString%'
                    ORDER BY last_name");

while ($row = $sth->fetch ()) { 

    $row_array = $row['last_name'].', '.$row['first_name'];

    array_push($return_arr,$row_array); 

}

echo json_encode($return_arr);

?>
  • 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-27T22:42:24+00:00Added an answer on May 27, 2026 at 10:42 pm

    To have an ID that is different from the (display) VALUE, you must return a JSON encoded array of objects like this:

    [
       {
          "id":"1",
          "value":"Doe, John"
       },
       {
          "id":"2",
          "value":"Smith, Mary"
       }
    ]
    

    You can then use ui.item.id to retrieve the selected ID.

    NOTE: You can also provide a “label” property that is different from the “value” property. Here’s the information from the documentation:

    The local data can be a simple Array of Strings, or it contains
    Objects for each item in the array, with either a label or value
    property or both. The label property is displayed in the suggestion
    menu. The value will be inserted into the input element after the user
    selected something from the menu. If just one property is specified,
    it will be used for both, eg. if you provide only value-properties,
    the value will also be used as the label.

    EDIT:

    I’m not a PHP guy, but I imagine the code to create the JSON array would be something like this:

    <?php
    $return_arr = array();
    
        ... snip ...
    
    while ($row = $sth->fetch ()) { 
        $row_array = array(
            "id" => $row['id'], 
            "value" => $row['last_name'].', '.$row['first_name']
        );
        array_push($return_arr, $row_array); 
    }
    echo json_encode($return_arr);
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a search box that doesn't have a submit button, I need to
I have a popup search box that is shown when the user mouses over
I have a simple search box that it hidden until hover(over) and hides again
I have a script for OS X 10.5 that focuses the Search box in
I have a UI with a search text box and a button that that
I have a search box that works great in WinForms, but is giving me
So I have a search box on my application to query the titles of
I have a WPF application with the autocomplete box via the toolkit (VS 2008).
I've got an MVC3 web application that has a general search box and displays
I have a little problem that i'm creating a simple search application which have

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.