JQuery Auto-Complete With TextChanged / OnBlur PostBack

I'm having a pretty nasty problem with an auto-completing textbox. I want to initiate an asynchronous PostBack whenever a user selects an item from the auto-completed field and retain the value of the item, rather than the text inputted. This works perfectly when enter is pressed rather than a mouse click.

An example of my issue:

Someone goes to the page, and types 1000 into the textbox. The autocomplete displays 10002, 1000B, and 10000. The user clicks on 1000B and an asynchronous PostBack initiates. Instead of 1000B, the TextBox.Text value is still 1000.

My assumption is that the textbox is initiating the PostBack before the value is actually getting assigned to it. I'm just curious if anyone has any possible solutions for what I'm talking about.

Answers


I fixed it in this manner:

As per another question on the site I added an autoPostBack parameter to the options list.

In bottom of the SelectCurrent() function, I added these lines.

    if (options.autoPostBackSelection == true) {
        __doPostBack($input.id, "");
    }

Then, my blur function looked like this:

    .blur(function() {
            hasFocus = 0;
            if (!config.mouseDownOnSelect) {
                hideResults();
            }
            if (options.autoPostBackSelection == true) {
                selectCurrent();
            }

I actually struggled with this for a bit, my Javascript/DOM event skills aren't very good. Hopefully this helps someone.


Need Your Help

Wrong syntax highlighting for PHP file in PHPStorm

php ide phpstorm

I don't know what happened but syntax highlighting for one php file stopped to working and also icon next to the file has changed. It shows it's text file instead of PHP .