开发者

jQuery - doing operation after user has selected a value

In my form, I have an autocomplete textbox field which sits in a div which is dynamically populated开发者_StackOverflow by AJAX and the autocomplete functionality is working fine. After the user has selected 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 can I achieve this?

Please see the 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 a function to do this operation, so I need to call this function after the user selects the autocompleted value.


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) );
          }
        });
    });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜