JQuery autocomplete> Select> Link

I have implemented this code, and I like it straight forward, because I plan to add ALOT to Source, but for life I can’t understand how to add the selected one as a link.

EG> Start Entering> AutoFill> Select> Go To This URL

Current code:

<!DOCTYPE html> <html> <head> <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script> <script> $(document).ready(function() { $("input#autocomplete").autocomplete({ source: ["NYC", "LA", "Philly", "Chitown", "DC", "SF", "Peru"] }); }); </script> </head> <body style="font-size:62.5%;"> <input id="autocomplete" /> </body> </html> 

I found some discussion about this here, but none of the code suggestions worked. How to add the URL associated with the values ​​above; I would like if I could support the same syntax and next to the values ​​that are just added; EG: "peru" www.peru.com

+4
source share
2 answers

You can add a url property for each object in the source array and then set window.location to this URL when the user selects an element:

 $(document).ready(function() { $("input#autocomplete").autocomplete({ source: [ { value: "NYC", url: 'http://www.nyc.com' }, { value: "LA", url: 'http://www.la.com' }, { value: "Philly", url: 'http://www.philly.com' }, { value: "Chitown", url: 'http://www.chitown.com' }, { value: "DC", url: 'http://www.washingtondc.com' }, { value: "SF", url: 'http://www.sanfran.com' }, { value: "Peru", url: 'http://www.peru.com' } ], select: function (event, ui) { window.location = ui.item.url; } }); }); 
+14
source
0
source

All Articles