tags:

views:

50

answers:

1

hi all, In my form, i have an autocomplete textbox field which sits in a div which is dynamically populated by ajax and the autocomplete functionality is working fine..after the user selecting the autocompleted value from the list in textbox, i need to do some operation on the same and get printed the resulted value on another textbox, how will i achieve this?

pls see code below

if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("waitimg").innerHTML="";
    document.getElementById("ajxform").innerHTML=xmlhttp.responseText;
    $(function(){ 
    $("#item_no").autocomplete("auto/finditem.cfm");

    })
       }

I have already created function to do this operation, so i need to call this function after the user selects the autocompleted value.

thanks in advance.

A: 

If you are using the jquery-ui autocomplete you do it like this...

$(function() {
    $("#item_no").autocomplete({
      source: "auto/finditem.cfm",
      select: function(even, ui) {
        $("#another_textbox").val(ui.item.value);
        alert( ui.item.value.substring(0, 10) );
      }
    });
});

The response that you get from the url defined in source can be in json format or have a format like this...

["ActionScript", "AppleScript", "Asp"] 

(more over here).

Try checking if the autocomplete is working as desired by using this test code....

$(function() {
        var availableTags = ["ActionScript", "AppleScript", "Asp"];
        $("#item_no").autocomplete({
          source: availableTags,
          select: function(even, ui) {
            $("#another_textbox").val(ui.item.value);
            alert( ui.item.value.substring(0, 10) );
          }
        });
    });
ShiVik
hi shiv, then how will achieve if i just want to take a substring of the selected one with the one u supplied, i am not clear about last select statement...pls help
soorajthomas
@sooraj - `select` I used is an event for autocomplete (more here - http://jqueryui.com/demos/autocomplete/). When user selects from an autocomplete suggestion, you can use the value `ui.item.value` for whatever purpose you want to. See the edited answer.
ShiVik
@sooraj - my mistake. now it should be fine.
ShiVik
ok, no probs, error gone, but now autocomplete is not working, i am missing anything!!!
soorajthomas
@sooraj - now it seems like autocomplete is not able to read the response that its getting from the url you have defined as source. Try using this webdebugger to see what you're getting in response `Fiddler` (http://www.fiddler2.com/fiddler2/).
ShiVik
nope, autocomplete is not fired off after entrering a letter in textbox, I watched this in firebug...
soorajthomas
@sooraj - Can you post some code how you're writing the script + html code?
ShiVik
hi, The autocomplete textbox and the other textbox are in a div which is generated by AJAX.
soorajthomas
i am using IE6 browser
soorajthomas
@sooraj - using IE6 does not help it, but I guess it shouldn't be a problem either. To isolate the problem, please try creating a simple file, not the ajax one. See if that works
ShiVik