To implement dynamic searching as the user types can be easily achieved using the typeahead plugin in javascript.
Include the following js file in your HTML page.
<script src="https://cdnjs.cloudflare.com/ajax/libs/typeahead.js/0.10.4/typeahead.bundle.min.js"></script>
Define an HTML element in your page.
<div class="search-bar"> <input type="text" name="searchBar" placeholder="Search"> </div>
Add the following code to the HTML page in the script tag.
$(".search-bar input[type='text']").typeWatch(showSuggestions); var showSuggestions = { callback : function(value) { if (value.length > 0) { $.ajax({ url : searchUrl, type : "post", data : { searchKey : value, }, success : function(data) { $('#searchSuggestions').html(data); } }); } else { $('.global-header .search-bar .suggestions-box').hide(); } }, wait : 750, highlight : true, captureLength : 0 }
Thanks
Archna Dhingra
More From Oodles
Ready to innovate? Let's get in touch
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Archna Dhingra
Archna is a bright Groovy and Grails developer and has worked on development of various SaaS applications using Grails framework.