views:

31

answers:

1

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.

A: 

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.

treefrog