Can't get the autocomplete search form to work -
I am implementing a search form that displays suggestions as if you start typing but it does work The problem is that when you start typing it does not show any suggestions Can you help me get the right code? thanks a lot!
This code is:
& lt; Script src = "// ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js" & gt; & Lt; / Script & gt; & Lt; Div & gt; & Lt; Input id = "auto-complete" type = "text" & gt; & Lt; / Div & gt; & Lt; Script & gt; {ID: "Yahoo", Value: "Yahoo"},], Minnamban: 1, Open: $ {"id =" "autocomplete}" {{id: "Google", value: "Google"}, Festival (event, UI) {$ ("ul.wi-autoproplate"). Unbind ("click"); Var data = $ (this) .data ("autocomplete"); Console.log (data); Var i = 0; I & lt; = Data. Options.source.length-1; I ++) {var s = data. Options.source [i]; $ ("Li.ui-menu-item a: includes (" + s .value + ")"). Attr ("href", "/" + s.id);}}}); / * $ ("Input # Autocompletion"). Bind ("Autocomplete Selection", Function (Event, UI) {//alert(ui.item.id + '-' + ui.item.value); //document.location .href = ui.item.id + '/' + Ui.item.value; //event.preventDefault;}); * / & Lt; / Script & gt;
Here is the code:
& lt; Div id = "search" & gt; & Lt; Input list = "result" id = "project" onkeydown = "if (event.keyCode == 13) {checkinput (this.value); return returned;}" /> & lt; / Div & gt; avaible results ...
& lt; Datalist id = "results" & gt; & Lt; Options & gt; Demo & lt; / Options & gt; & Lt; Options & gt; Example & lt; / Options & gt; & Lt; Options & gt; Pizza & lt; / Options & gt; & Lt; / DataList & gt; Finally javascript
function checkinput (search) {if (searchQuery == "home") {window.location = "Home.html"; } And if (searchquant == "contact") {window.location = "Contact.html"; } And if (the detective == "sitemap") {window.location = "Sitemap.html"; } And {window.location = "noresult.html"; }} In this way, when a person goes in search, they have limited options in the pre-populated list, and whatever they choose will take them to your targeted page is! I can not take all the credit, but I hope that helps!
Comments
Post a Comment