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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:45:55+00:00 2026-05-22T18:45:55+00:00

I have a jquery’s autocomplete texbox and, upon a click of a button, I

  • 0

I have a jquery’s autocomplete texbox and, upon a click of a button, I need to check if the value entered has come from the autocomplete or is it a completely new value.

The problems is that my code constantly gives me ‘alert(“no”)’… maybe I shouldn’t be checking against ‘cache’, but something else?

//////////////////////////////////////////// autocomplete code //////////////////
        var cache = {},
            lastXhr;
        $( "#inputV" ).autocomplete({
            minLength: 2,
            source: function( request, response ) {
                var term = request.term;
                if ( term in cache ) {
                    response( cache[ term ] );
                    return;
                }

                lastXhr = $.getJSON( "search.php", request, function( data, status, xhr ) {
                    cache[ term ] = data;
                    if ( xhr === lastXhr ) {
                        response( data );
                    }
                });
            }
        });


////////////////////////// check if input comes from autocomplete  //////////////////
        $('#btn_check').click(function()        {

            var input = $("#inputV").val();
            alert(input);

            if ( input in cache ) 
                {
                    alert("yes");
                 }  
                else
                {
                    alert("no");
                }   
        });

enter image description here

  • 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-22T18:45:56+00:00Added an answer on May 22, 2026 at 6:45 pm

    This is how I make it on a project of mine

    function lookup(inputString) {
        $.post('/getSuggestions', {
            queryString: ""+inputString+""
        }, function(data){
            if(data.length >0) {
                $("#suggestions").show();
                $("#autoSuggestionsList").html(data);
            }
        });
    }
    
    function fill(thisValue,thisID) {
        $("#inputString").val(thisValue);
        $("#id").val(thisID);
        $("#suggestions").hide();
    }
    

    Where the fill() function is attached to returned results from the autocomplate. So if user clicks on an item from the list, the fill function will set the value in my html element with id “id” using this $("#id").val(thisID);

    Simply if user doesn’t use the suggest from the list, the “id” will not be filled. In your case you can just add an hidden input with name/id “isacutocomplate”, attach fill(); function to results returned from the autocomlate and if item is clicked, you will update the “isacutocomplate”, other way you will not fill it. So, when user click your button, you check the “isacutocomplate” input value and you see if it’s from autocomplate’s list or not.

    Hope that make sense to you. If not, I can provide entire process.

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

Sidebar

Related Questions

I have JQuery slide in-out div, which slides in-out on click of a button
I have jquery code that runs everytime everytime I click on my button but
I have jQuery code which looks something like this on Button1 Click $('table.result_grid tbody
I have jQuery dialog window, upon some operations I have a blockUI plugin which
I have jquery tabs, in which one tab has an iframe and the other
I have jQuery but I'm not sure if it has any built-in sorting helpers.
I have jQuery based template from themeforest and i building on this ASP.NET Web
I have jquery grabbing an id from something else (image) and I would like
I have jquery function as validationtype its working fine <script type=text/javascript> jQuery.validator.addMethod(mytest, function (value,
I'm trying to have jQuery autocomplete point to a PHP file (which gathers data

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.