Reputation: 13
In my page I am using ajax to generate/show a textbox after button click. I am using autocomplete functionality in this textbox, but autocomplete call is not firing off. I cannot see the autocomplete call in firebug when I try to enter anything in the textbox.
But at the same time it is working fine in a plain test page which has a textbox (without ajax generation), so that means jQuery, autocomplete files are okay.
I am suspecting ajax generated textbox's ID should be called in autocomplete function in a different way. I have attached below what way I tried.
<script>
$(function(){
$("#orderingparty2").autocomplete("auto/findparty.cfm");
})
</script>
Upvotes: 1
Views: 1309
Reputation: 5842
Bind the code adding autocomplete to the ajax function which is generating the input box. Else you can trigger the autcomplete event on any event like onclick.
$("#orderingparty2").live('click',function(event)
{
$(this).autocomplete("auto/findparty.cfm");
});
Upvotes: 3
Reputation: 10940
You have to attach the autocomplete call in the ajax handler that appends the textbox, something like this:
$.ajax({
...
success(function(...) {
$('<input type="text">')
.attr(...)
.css(...)
.appendTo('#myForm')
.autocomplete("auto/findparty.cfm");
})
...
});
Upvotes: 0