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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:35:28+00:00 2026-05-30T03:35:28+00:00

i can’t figure out how to make select method for the jquery ui autocomplete

  • 0

i can’t figure out how to make select method for the jquery ui autocomplete library work. i’ve tried to put together a test case, but for some reason (xsrf?) the test isn’t bringing results. my problem isn’t getting results and displaying them (that works fine when i make the request on the same domain), my problem is that, after i get the results in a drop down menu, nothing happens when i click on one of the results.

test.js

<html><body>

<script type="text/javascript" src="./jquery-1.7.1.min.js"> </script>
<script type="text/javascript" src="./jquery-ui-1.8.17.custom.min.js"> </script>
<link rel="stylesheet" href="./jquery-ui.css" />
<script type="text/javascript" >

    var cwJQ = jQuery.noConflict();

    cwJQ(document).ready(function() {

        $input = cwJQ('input#last_name');

        var renderItemOverride = function (ul, item) {
                return cwJQ("<li></li>")
                        .data("item.autocomplete", item)
                        .append( item.label )
                        .appendTo(ul);
        };

        $input.autocomplete( {  
                source: function( req, res ) {
                        cwJQ.ajax( {
                                url: 'http://news.google.com/news/search',
                                dataType: 'html',
                                data: {  "q": req.term
                                },
                                success: function(data) {
                                        var datum = new Array;
                                        cwJQ(data).find('a').each( function( i, val ) {
                                                datum.push( "<span name='li-span'>" + cwJQ( val ).text() + "</span>" );
                                        } );
                                        res( datum );
                                }
                        } )
                },
                select: function( event, ui ) {
                        alert();console.log();
                },
                minLength: 2
        } ).data('autocomplete')._renderItem = renderItemOverride;

        cwJQ("#li-span").live( 'click', function() {
                console.log( this );
        } );
    });

</script>

        <form> 
                <label class="autocomplete weight-normal">By last name</label>
                <input type="text" name="last_name" size="35" class="width-full" id="last_name" />
        </form>

</body></html>

jquery-ui.css

.ui-menu {
        padding: 0px;
        background-color: #FFF;
        overflow: hidden;
}

ul.ui-menu {
        display: block;
        list-style-position: outside;
        list-style: none;
        padding: 0;
        margin: 0;
        border: 1px solid #998F87;
        overflow: auto;
        max-height: 200px;
        width: 200px;
}

ul.ui-menu li {
        margin: 0px;
        padding: 3px 5px;
        cursor: pointer;
        display: block;
        font-size: 12px;
        overflow: hidden;
}

span#undefined {
        display: block;
        background-color: #ffff00;
        width: 100%;
        margin: 0;
}

ul.ui-menu li:hover { background: #ff00ff; }

EDIT

The working code is:

    var cwJQ = jQuery.noConflict();

cwJQ(document).ready(function() {

    $input = cwJQ('input#last_name');

    $input.autocomplete( {
        source: function( req, res ) {
            cwJQ.ajax( {
                url: 'url',
                dataType: 'html',
                data: {  "name": req.term,
                    "name_in_id": 1
                },
                success: function(data) {
                    var datum = new Array;
                    cwJQ(data).find('li').each( function( i, val ) {
                        datum.push( { value: cwJQ( val ).text(), id: val.id.split('_')[1] } );
                    } );
                    res( datum );
                }
            } )
        },
        select: function( event, ui ) {
                            if( ui.item.id != undefined ) {
                addMemDat( ui.item.id, ui.item.value );
            }
        },
        search: function() {
            cwJQ( this ).addClass("auto_complete_loading");
        },
        open: function(event, ui){
            cwJQ( this ).removeClass("auto_complete_loading");
        },
        close: function() {
            $input.val('');
        },
        minLength: 2
    } ).data( "autocomplete" )._renderItem = function( ul, item ) {
    return cwJQ( "<li></li>" )
        .data( "item.autocomplete", item )
        .append( "<a><span id='" + item.id + "'>" + item.value + "</span></a>" )
        .appendTo( ul );
    };
});

ie, the _renderItem override was not correct (but there’s also the add/remove of the autocomplete class with some simple css to display a spinner in the input box while results are being retrieved.

  • 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-30T03:35:30+00:00Added an answer on May 30, 2026 at 3:35 am

    Can you try this:

      datum.push({ value: "<span name='li-span'>" + cwJQ( val ).text() + "</span>" });
    

    instead of this:

      datum.push( "<span name='li-span'>" + cwJQ( val ).text() + "</span>" );
    

    It works for me…

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

Sidebar

Related Questions

Can't work out a way to make an array of buttons in android. This
Can anyone help me trying to find out why this doesn't work. The brushes
Can anyone recommend a good library for generating an audio file, such as mp3,
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
Can I call a java class method from inside a flash movie?
Can some one Guide me to work with these things... What is Model popup
can anyone tell me why this doesn't work? db = openOrCreateDatabase(database.db, SQLiteDatabase.CREATE_IF_NECESSARY, null); db.setLocale(Locale.getDefault());
Can we put functions to determine the condition for our list comprehensions. Here is
can someone show me the regex for this preg_match. I want to make sure

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.