Link to home
Start Free TrialLog in
Avatar of Andrew
AndrewFlag for United States of America

asked on

jquery autocomplete forcing the user to select an item from the list

Looking for some help to force user to select an item from a jquery autocomplete textbox.  What I have found doesn't seem to work for me & I am not sure why.

Here is a demo:  http://members.gcp21.org/autocomplete.aspx

    <script type="text/javascript">
        $(document).ready(function () {
            $("#dtv_Country").autocomplete({
                source: function (request, response) {
                    $.ajax({
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        url: "autocomplete.aspx/getCountries",
                        data: "{'prefixText':'" + $("#dtv_Country").val() + "'}",
                        dataType: "json",
                        success: function (data) {
                            response(data.d);
                        },
                        error: function (result) {
                            alert("Error");
                        },
                        select: function (e, ui) {
                                $(this).next().val(ui.item.id);
                        },
                        change: function (ev, ui) {
                        if (!ui.item)
                            $(this).val("");
                    }
                  });
                }
            });

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Andrew

ASKER

I'm sorry,  jQuery is not my strong point at all.  Do you happen to have a link to an example by chance?
How you imagine to do this?Give us an example to help you.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Andrew

ASKER

Sorry David,  I accidentally selected the incorrect solution when closing...