views:

107

answers:

2

I am using autocomplete feature in jquery to show the users list intellisense.

for formatItem, i am using FirstName + " " + LastName + " [" + EmailAddress + "]"; for formatResult, i am showing FirstName + " " + LastName

I need to get the selected users userid, how can i get in autocomplete feature?

Say, I have a textbox to enter the name of the user with autocomplete functionality. And a button near the textbox to add the entered user's userid to the database. I need to show only the FirstName + " " + LastName in textbox and while saving it i need to use userid.

Where can i store the Useridfor the User entered in the textbox?

A: 

you can have a hidden field. When user selects the value you can get User ID and put it into hidden field. On button's click pass the value of hidden field with text box.

TheVillageIdiot
+1  A: 

Here's actual code from a current project

    $("#venue_name").autocomplete(self._venueAutoCompleteUrl, {
        multiple: false,
        autoFill: true,
        scroll: true,
        parse: function(data) {
            return $.map(eval(data), function(row) {
                return { data: row, value: row.Name, Id: row.Id, result: row.Name }
            });
        },
        formatItem: function(item) {
            return "<strong>" + item.Name + "</strong><br/>" + item.Address;
        },
        formatResult: function(row) { return row.Id; }
    }).result(function(e, item) {
        $("#selected_venue_address").show();
        $("#selected_venue_address").html("<small>" + item.Address + "</small><br/>");
        $("#Event_Venue").val(item.Id);
    });

Notice the last part (.result(function(e, item){} )

The last part sets the venue id to the hidden field Event_Venue

JBland