[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Verify AutoComplete Selected

Posted on 2013-11-07
1
Medium Priority
?
216 Views
Last Modified: 2013-11-12
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

0
Comment
Question by:NickMalloy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 82

Accepted Solution

by:
leakim971 earned 1600 total points
ID: 39632116
add this :

$("form").submit(function(evt) {
     if( $("#<%=txtSearch.ClientID%>").val().length == 0 ) {
            alert("please search a client");
            evt.preventDefault();
     }
})

Open in new window


 
$(document).ready(function () {

$("form").submit(function(evt) {
     if( $("#<%=txtSearch.ClientID%>").val().length == 0 ) {
            alert("please search a client");
            evt.preventDefault();
     }
})

            $("#<%=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

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question