sw6 - KTBFFH sw6 - KTBFFH - 2 years ago 89
jQuery Question

Execute function on option selected from jQuery ui autocomplete option list

Hi I have the code below for autocomplete which works fine but my only issue is that when a user clicks on an option from the autocomplete list, it should trigger another function (doSomething()). This however is not being done. Granted if the user makes a selection and presses "enter" the function is executed.

var url = "http://myURL";
var field = "myField";

$(document).ready(function () {
source: function (req, add) {
var suggestions = search(req.term, url, field);
select: function( event, ui ) {


function search(value, listurl, field) {
var coll = new Array();
var url =
listurl + "?$filter=startswith(" + field + ",'" + value + "')";

cache: true,
type: "GET",
async: false,
dataType: "json",
url: url,
success: function (data) {
var results = data.d.results;
for (att in results) {
var object = results[att];
for (attt in object) {
if (attt == field) {

return coll;}

function doSomething() {

Thanks for any suggestions.

Answer Source

Got this resolved like this:

$('#tags').on('keyup change', function () {

$('#tags').on('autocompleteselect', function (e, ui) {

Thanks to this SO link

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download