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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:16:01+00:00 2026-06-05T08:16:01+00:00

Am using ui autocomplete from http://jqueryui.com/demos/autocomplete/#remote Using PHP in search.php to return results. Am

  • 0

Am using ui autocomplete from http://jqueryui.com/demos/autocomplete/#remote
Using PHP in search.php to return results.

Am trying to get my custom output of

<li>Company Name | Contact Name</li>

This is coming from the following code:

if(is_array($rs) && count($rs) > 0){
        foreach ($rs as $item) {
            //format: "Name Surname=>cid_uid"
            $json = array();
            $json['id'] = $item['parentCompanyId'].'_'.$item['uid'];
            $json['label'] = $item['companyName'] . ' | ' . $item['name'] . ' ' . $item['surname'];
            $data[] = $json;
        }
    }

This works fantstically well, however to make it easier to read results, I would like to rather have results on 2 lines within the < li > tags, so that its more like this:

<li>
Contact Name<br>
Company Name | Department Name
</li>

I’ve tried the following:

$json['label'] = $item['name'] . ' ' . $item['surname'] . '\n' .$item['companyName'];

and

$json['label'] = $item['name'] . ' ' . $item['surname'] . '<br>' .$item['companyName'];

and

$json['label'] = $item['name'] . ' ' . $item['surname'] . '\\n' .$item['companyName'];

All tries result in the list either showing the actual <br> tag or \n rather than pushing to the next line.

Viewing source with firebug shows Name&lt;br&gt;Company

Not sure if this is happening because of the:

header("Content-type: application/json");
echo json_encode($data);

Please note, my question is related to getting the HTML output to produce 2 lines within a <li> tag via autocomplete/php/json .. I’m not asking about how to add Department Name..Hope I’m making sense..

Ta

  • 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-05T08:16:02+00:00Added an answer on June 5, 2026 at 8:16 am

    Override the _renderItem method:

    $("#autocomplete").autocomplete()
        .data( "autocomplete" )._renderItem = function( ul, item ) {
            return $( "<li></li>" )
                .data( "item.autocomplete", item )
                .append( item.label )
                .appendTo( ul );
        };
    

    This demo from the documentation does the same thing: http://jqueryui.com/demos/autocomplete/#custom-data

    By default, .append( item.label ) is .text( item.label ) which is why your <br /> gets replaced with &lt;br /&gt;

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

Sidebar

Related Questions

I'm using the autocombox from the jQuery UI library (http://jqueryui.com/demos/autocomplete/#combobox). The combobox is replacing
I m using autocomplete from http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/ i managed to get data from server in
I'm using the jquery autocomplete plugin from pengoworks: http://www.pengoworks.com/workshop/jquery/autocomplete_docs.txt In the function called upon
I'm using the jQuery Autocomplete plugin from http://docs.jquery.com/Plugins/Autocomplete on IE7 and it's not releasing
I'm using the jQueryUI autocomplete widget to get data from a JSON web service.
I am using jQuery auto-complete. I have download this script from http://code.google.com/p/jquery-autocomplete/ . I
So I'm using a custom auto suggest component that I found online at http://hillelcoren.com/flex-autocomplete/
I am using jQuery autocomplete from here : http://www.pengoworks.com/workshop/jquery/autocomplete.htm $(#TestTextbox).autocomplete( '<%= Url.Action(LookupAction) %>', {
I am trying to use autocomplete from http://dev.jquery.com/view/trunk/plugins/autocomplete/jquery.autocomplete.js but am getting this error. textbox
hi i am using Ajax AutoComplete for jQuery library http://www.devbridge.com/projects/autocomplete/jquery/ there are 2 demos

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.