user3140252
user3140252

Reputation: 111

autocomplete ajax - update input with a specified value

i have an problem with my autocomplete script:

If I search for example for "siegg" I get this information back

it's okay

but, I don't what the full finded results written in the textbox

it's not okay

so, this is what i want:

it's okay

Here are my javascript code:

$("#place_RegisterUser").autocomplete({
    source: function( request, response ) {
        $.ajax({
            url: 'webservice.php?method=GetAllAddressData&filter=' + $("#place_RegisterUser").val(),
            dataType: "json",
            data: {term: request.term},
            success: function(data) {
                response($.map(data.Values, function(item) {
                    return {
                        label: item.PlaceZIP + ", " + item.PlaceName + ", Bezirk " + item.CountyName,
                        PlaceZIP: item.PlaceZIP,
                        CountyName: item.CountyName,
                        FederalStateName: item.FederalStateName,
                        CountryName: item.CountryName
                        };
                }));
            }
        });
    },
    minLength: 2,
    select: function(event, ui) {
        $('#zipcode_RegisterUser').val(ui.item.PlaceZIP);
        $('#county_RegisterUser').val(ui.item.CountyName);
        $('#federalstate_RegisterUser').val(ui.item.FederalStateName);
        $('#country_RegisterUser').val(ui.item.CountryName);
    }
});

Upvotes: 1

Views: 388

Answers (1)

user2321864
user2321864

Reputation: 2307

In your select callback add

$("#place_RegisterUser").val(ui.item.PlaceName);
return false;

http://api.jqueryui.com/autocomplete/#event-select The default action of the select event is to replace the text field's value with the value of the selected item.

return false from this event prevents the value from being updated. so you need to set it yourself.

Upvotes: 2

Related Questions