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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:31:28+00:00 2026-06-15T07:31:28+00:00

I am debugging a jQuery autocomple instance (v1.1) on a city input field. The

  • 0

I am debugging a jQuery autocomple instance (v1.1) on a “city” input field.

The autocomplete data binding is set on the keyup event of the field, only if the field value length is at least 2 and only if the value has changed.

The data binding, the hints list and the autocomplete are working fine.
But something is wrong. In the log I see that many times the 3rd and some times even the 4th character is missing in the city input value posted to the server. Some examples:

"trpani" instead of "trapani"
"fienze" instead of "firenze"
"scndicci" instead of "scandicci"
"brdisi" instead of "brindisi"
"paermo" instead of "palermo"
"caliari" instead of "cagliari"

I do not succeed in replicate the bug, but I am sure it cannot be by chance! The error occurs just at the 3rd character. It seems that during the insert, Javascript processing collides with the keyboard buffer.

So, I guess but I am not sure, people type f i r e n z e, but eventually the r character is missed, and the final value of the input is fienze that is eventually posted to the server.

Question

What is happening? Why I do not succeed in replicate the error? What is wrong?

Here is the code used to set the autocomplete:

/*
 * here I store the previous value
 */
var storeCity;
$('#City').keydown(function(){
    var val = $(this).val();
    storeCity = (val.length >=2 ? val.substring(0,2):"");
});

/*
 * the autocomplete is set only if
 * - the City value has changed compared to the storeCity value
 * - the City value has lenght at least 2
 * - remark: using the keypress does not solve the issue
 */
$('#City').keyup(function(){
    var val = $(this).val();
    if(val.length>=2 && val.substring(0,2)!=storeCity){
        getLocations('#City');
    }
});

function getLocations(cityId){
    var hint = $(cityId).val().substring(0,2);

    $.ajax({
        type: "GET",
        url: "/include/getLocations.asp",
        data: ({location : hint}),
        async: false,
        error: function() {},
        success: function(dataget) {
            var result = dataget.split("\n");

            $(cityId).flushCache();
            $(cityId).autocomplete(result, {
                pleft: 100px,
                minChars: 2,
                matchContains: true,
                max: 3000,
                delay: 100,
                formatItem: function(row){...},
                formatMatch: function(row){ return row[0]; },
                formatResult: function(row){ return row[0]; }
            });

            $(cityId).result(function(event,data){...});
        }
    });
}
  • 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-15T07:31:29+00:00Added an answer on June 15, 2026 at 7:31 am

    Eventually I resolved with some heuristics. I thought that the problem is due to events conflict. So I tryed to get better performance.

    • initialize the autocomplete once, outside the getLocation() method
    • store the $(‘#city’) object in a variable
    • put the $city.result method outside the getLocation() method

    Here is the result code:

    var $city = $('#City');
    var storeCity;
    
    $city.keypress(function(){
        var val = $(this).val();
        storeCity = (val.length >=2 ? val.substring(0,2):"");
    });
    
    /*
     * the autocomplete is set only if
     * - the City value has changed compared to the storeCity value
     * - the City value has lenght at least 2
     * - remark: using the keypress does not solve the issue
     */
    $city.keyup(function(){
        var val = $(this).val();
        if(val.length>=2 && val.substring(0,2)!=storeCity){
            getLocations('#' + $city[0].id);
        }
    });
    
    $city.autocomplete({
        pleft: 100px,
        minChars: 2,
        matchContains: true,
        max: 3000,
        delay: 50
    });
    
    $city.result(function(event,data){...});
    
    function getLocations(cityId){
        var hint = $(cityId).val().substring(0,2);
    
        $.ajax({
            type: "GET",
            url: "/include/getLocations.asp",
            data: ({location : hint}),
            async: false,
            error: function() {...},
            success: function(dataget) {
                var result = dataget.split("\n");
    
                $(cityId).flushCache();
                $(cityId).autocomplete(result, {
                    formatItem: function(row){...},
                    formatMatch: function(row){ return row[0]; },
                    formatResult: function(row){ return row[0]; }
                });
            }
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using jquery.ui.autocomplete on multiple comboboxes on a page. In IE only, the
While debugging jQuery apps that use AJAX, I often have the need to see
Hey everyone, I'm not the best at Jquery debugging, so I was hoping someone
what tools do you use for writing jquery code and testing/debugging your code?
I recently ran into a familiar javascript/jQuery timing bug and spent too long debugging
I'm trying to use struts2-jquery grid plugin. When debugging my gridmodel is getting updated
Greetings, I am using the official Autocomplete jquery widget and am having troubles dynamically
After just now spending too much time debugging why my jQuery animate() calls stopped
While debugging a javascript code that uses jQuery I found the following code: [0,
every time i try using jquery dialog i get error null when debugging using

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.