Link to home
Start Free TrialLog in
Avatar of NickMalloy
NickMalloyFlag for United States of America

asked on

Verify AutoComplete Selected

I'm trying to prevent users from submitting a form without selecting something from my autocomplete. I don't want free text in my searchbox.

So far I can't get my code to work. what can I do to prevent

 $(document).ready(function () {
            $("#<%=txtSearch.ClientID%>").autocomplete("Search.ashx", {
                 extraParams: { "type": function () { return $("input:radio[name='toggle']:checked").val(); } },
                 width: 200,
                 formatItem: function (data, i, n, value) {
                     return "<img style = 'width:50px;height:50px' src='Images/doctypes/" + value.split(",")[1] + ".png'/> " + value.split(",")[0];
                 },
                 formatResult: function (data, value) {
                     return value.split(",")[0] + " # " + value.split(",")[2]
                 },
                 select: function (e, ui) {
                     alert(ui.item.value);
                 }
                 



            });

            $("#<%=txtSearch.ClientID%>").result(function (event, data, formatted) {
                if (data) {
                    $("#<%=hfSelected.ClientID%>").val("1");
                    $("#<%=tester.ClientID%>").html("Done");
                    //auto-complete matched

                }
                else {
                    $("#<%=hfSelected.ClientID%>").val("0");
                    $("#<%=tester.ClientID%>").html("Not Done");
                    //there was no match
                }
            });

            $("#<%=txtSearch.ClientID%>").blur(function () {
                $("#<%=txtSearch.ClientID%>").search(); //trigger result() on blur, even if autocomplete wasn't used
       
            });


         });

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe 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