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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:13:17+00:00 2026-06-17T23:13:17+00:00

I’m having trouble modifying a script from a book (jQuery UI by Eric Sarrion),

  • 0

I’m having trouble modifying a script from a book (jQuery UI by Eric Sarrion), the book sets up a database (mysql), which outputs an xml document formatted as

<books>
<li>
<title>Annie</title>
<picture>annie.jpg</picture>
</li>
</books> 

Because I want to pass the autocomplete result to script which loads details on “annie”, I want to pass the database ID rather than a title, so modified the database to include an id, then altered the output xml to

<books>
<li>
<id>123456</id>
<title>Annie</title>
<picture>annie.jpg</picture>
</li>
</books> 

I have further altered the code so it adds the attr id=”123456″ to the li tag of autocomplete, like this

<ul class="ui-autocomplete ui-menu ui-widget ui-widget-content ui-corner-all" role="listbox" aria-activedescendant="ui-active-menuitem" style="z-index: 1; top: 209px; left: 969px; display: block; width: 400px;">
<li class="ui-menu-item" role="menuitem" **id="123456"**>
<a class="ui-corner-all" tabindex="-1">
<img src="./annie.jpg" height="30">
<span style="position:relative;top:-7px;left:10px">Annie</span>
</a>
</li>
</ul>

However I am now having trouble putting the ID into a hidden form input, ready to pass to the details script.

I was hoping to be able to do something like

select:function(event, ui) {
    console.log("Name: " + ui.item.value + " Id: " + ui.item.id);
}

The more I read this book, the more I think it was a mistake, there are many many html errors, some php errors, poor formatting. I’m not sure if its just my background in server side languages or this book which is making this so difficult.

The jQuery code is as follows.

// JavaScript Document
$(document).ready(function() {
$("input#search-text").autocomplete ({
source : function (request, callback){
var data = { term : request.term };
$.ajax ({
url : "./action.php",
data : data,
complete : function (xhr, result){
if (result != "success") return;
var response = xhr.responseXML;
var books = [];
$(response).find ("li title").each (function ()
{books.push ($(this).text ());});
callback (books);
var $ul = $("input#search-text").autocomplete ("widget");
$(response).find ("li picture").each (function (index) {
var src = $(this).text () || "default.jpg";
$ul.find ("li:eq(" + index +") a").wrapInner ("<span style=position:relative;" + "top:-7px;left:10px></span>").prepend ("<img src=./images/" + src + " height=30 />");});
$(response).find ("li id").each (function (index) {
    var id = $(this).text () || "0";
    $ul.find("li:eq("+index+")").attr('id',id);
});
}
});
},
open : function (event){
var $ul = $(this).autocomplete("widget");
$ul.blur(function(event) {});
$ul.show ().slideDown (600);
$ul.css ("width", "400px");
},
select:function(event, ui) {
    console.log("Selected: " + ui.item.value + " aka " + ui.item.id);
}
});
});

Any suggestions for better books or a better way of doing this would be welcome 🙂

  • 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-17T23:13:19+00:00Added an answer on June 17, 2026 at 11:13 pm

    I solved this problem by switching from xml to json, was a bit of a hassle but using this code instead now…

    //autocomplete code
        $("#search-text").autocomplete({
            source: "./action.php",
            minLength: 3,
            delay: 300,
            max:10,
    
            select: function(event, ui) {
                $('#search-value').val(ui.item.id);
                //$('#picture').val(ui.item.picture);
            }
    }).data("autocomplete")._renderItem = function (ul, item) {
            return $("<li />")
                .data("item.autocomplete", item)
                .append("<a><img height='30' src='./images/" + item.picture + "' /><span style=position:relative;" + "top:-7px;left:10px>" + item.label + "</span></a>")
                .appendTo(ul);
    }; 
    
    
        });
    

    with json output like

    [{"id":"123456","value":"annie","picture":"annie.jpg"}]
    

    Because max:10 doesn’t work, I added a limit of 10 to the mysql query.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have an autohotkey script which looks up a word in a bilingual dictionary
I have a text area in my form which accepts all possible characters from
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a view passing on information from a database: def serve_article(request, id): served_article
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I am reading a book about Javascript and jQuery and using one of the
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

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.