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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:01:56+00:00 2026-06-16T06:01:56+00:00

I took most of this code from jQuery UI documentation. I want to add

  • 0

I took most of this code from jQuery UI documentation.
I want to add to the request variables such that the <input> id is also sent.

Input looks like this:

<input size="50" class="attr_values" name="msrp" id="msrp" />

Now here’s the jquery. Inside of .autocomplete source $.getJSON I try to use “this.id” and it doesn’t work. How can I get this to work?

$(document).ready(function() { 
    // 2 string parsing functions
    function split( val ) {
        return val.split( /,\s*/ );
    }
    function extractLast( term ) {
        return split( term ).pop();
    }


    $( '.attr_values' )
        // 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( 'controllers/core_data/ajax/core_data.php', {
                    'attr_name' : this.id, // THIS DOESN'T WORK
                    'term': extractLast( request.term )
                }, response );
            },
            search: function() {
                // custom minLength
                var term = extractLast( this.value );
                if ( term.length < 2 ) {
                    return false;
                }
                // var attr_name = this.id;
            },
            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;
            }
        });

 });

Also note that I have applied this to the “.attr_values” class rather than to one particular id like the examples show. I have a whole bunch of fields, each with a different id. That’s why I need to send the id AND term to the php script. So that it knows which table to look the term up in.

  • 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-16T06:01:58+00:00Added an answer on June 16, 2026 at 6:01 am

    this doesn’t refer to the original collection anymore inside the getJSON callback. Try drilling upward to get to the original element:

    source: function( request, response ) {
        $.getJSON( 'controllers/core_data/ajax/core_data.php', {
            'attr_name' : this.element[0].id,
            'term': extractLast( request.term )
        }, response );
    },
    

    The context this here refers to the autocomplete object that you are evaluating the source function for. We can use the element property to get the corresponding jQuery collection, and then find the id from that.

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

Sidebar

Related Questions

There is code that I want to include in most of my projects. Things
I took this piece from an unencrypted .DAT file: Code: 00 e1 27 17
I took the example code from the Kendo UI demos at http://demos.kendoui.com/web/grid/remote-data.html , binding
Starting my RestKit development, trying to make the very first request. Took this sample
I have a piece of code that looks like this: downloadsByExtensionCount = defaultdict(int) downloadsByExtensionList
I have an input file that I want to sort based on timestamp which
it took me some time to find out that both Eclipse and Aptana get
I took the rendered page from the SWT Browser and exported it to an
I took a look at this answer and it goes in part to solving
I took some code here: Check if role consists of particular user in DB?

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.