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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:47:12+00:00 2026-05-25T06:47:12+00:00

I have form autocomplete code that executes when value changes in one textbox. It

  • 0

I have form autocomplete code that executes when value changes in one textbox. It looks like this:

$('#myTextBoxId)').change(function () {
    var caller = $(this);
    var ajaxurl = '@Url.Action("Autocomplete", "Ajax")';
    var postData = { myvalue: $(caller).val() }
        executeAfterCurrentAjax(function () {
            //alert("executing after ajax");
            if ($(caller).valid()) {
                //alert("field is valid");
                $.ajax({ type: 'POST',
                    url: ajaxurl,
                    data: postData,
                    success: function (data) {
                        //some code that handles ajax call result to update form
                        }
                    });
                }
            });
        });

As this form field (myTextBoxId) has remote validator, I have made this function:

function executeAfterCurrentAjax(callback) {
    if (ajaxCounter > 0) {
        setTimeout(function () { executeAfterCurrentAjax(callback); }, 100);
    }
    else {
        callback();
    }
}

This function enables me to execute this autocomplete call after remote validation has ended, resulting in autocomplete only when textbox has valid value. ajaxCounter variable is global, and its value is set in global ajax events:

$(document).ajaxStart(function () {
        ajaxCounter++;
    });
$(document).ajaxComplete(function () {
        ajaxCounter--;
        if (ajaxCounter <= 0) {
            ajaxCounter = 0;
        }
    });

My problem is in IE (9), and it occurs only when I normally use my form. Problem is that function body inside executeAfterCurrentAjax(function () {…}); sometimes does not execute for some reason. If I uncomment any of two alerts, everything works every time, but if not, ajax call is most of the time not made (I checked this by debugging on server). If I open developer tools and try to capture network or debug javascript everything works as it should.

  • 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-25T06:47:12+00:00Added an answer on May 25, 2026 at 6:47 am

    It seems that problem occurs when field loses focus in the same moment when remote validation request is complete. What I think it happens then is callback function in executeAfterCurrentAjaxCall is executed immediately, and in that moment jquery validation response is not finished yet, so $(caller).valid() returns false. I still do not know how alert("field is valid") helps in that scenario, and that could be sign that I’m wrong and something else is happening. However, changing executeAfterCurrentAjaxCall so it looks like this seems to solve my problem:

    function executeAfterCurrentAjax(callback) {
        if (ajaxCounter > 0) {
            setTimeout(function () { executeAfterCurrentAjax(callback); }, 100);
        }
        else {
            setTimeout(callback, 10);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form like this: <form name=mine> <input type=text name=one> <input type=text name=two>
I have form that displays several keywords (standard set of choice lists that changes
imagine i have one textbox (with autocomplete 1.1, not the latest UI version) and
I have the following code: $(#auto).autocomplete({ source: js/search.php, minLength: 3 }); This code is
this is some form generation code. I would like to add a captcha or
I have a form in C# that has a button that, when clicked, I
I have a form with some radio buttons that are disabled by default. When
I have a form element that contains multiple lines of inputs. Think of each
I have a form that contains a GridView control which is databound to an
I wrote code that fails to use the JQuery autocomplete to fire a result

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.