Reputation: 34287
I have created a simple jquery-ui autocomplete demo.
QUESTION
How can I cause a postback to occur when an option is selected from the list?
HTML
<select id="ddl"></select>
<input id="field" type="text"></input>
JQUERY
$("#field").autocomplete({
select: function(event, ui) {
__doPostBack("#ddl", ""); //Postback will not occur here?
}
});
NOTES
The rest of the code in this demo is not required, it is simply there to show that an option is being successfully selected.
I can't see what is preventing the postback from occuring. I simply want a postback to occur when the user picks any option from the list generated by the autocomplete.
Upvotes: 2
Views: 2503
Reputation: 847
Adding values to the autocomplete widget fixed it for me.
Note that the "select" function only fires when I click on one of the autocomplete options. It does not fire if I only type in the name of one of the options.
Check out the updated code below:
<select id="ddl" />
<input id="field" type="text" />
<script type="text/javascript">
var availableAutocompleteValues = [
"jquery",
"java",
"javascript"
];
$("#field").autocomplete({
source: availableAutocompleteValues
});
$("#field").autocomplete({
select: function (event, ui) {
__doPostBack("#ddl", ""); //Postback will not occur here?
}
});
</script>
Upvotes: 1