/    Sign up×
Community /Pin to ProfileBookmark

Autocomplete not opening link

Hi there

Im a relative newbie and am trying to have a searchbar that users can complete, with the text entry being from a pre-defined list. The hope is that a new page will open with the link that relates to the search bar entry.

Im using an Autocomplete code but cant work out how to get the link part to work. See below code

[CODE]<html>
<head>
<script src=”jquery-latest.js”></script>
<link rel=”stylesheet” href=”http://dev.jquery.com/view/trunk/plugins/autocomplete/demo/main.css” type=”text/css” />
<link rel=”stylesheet” href=”http://dev.jquery.com/view/trunk/plugins/autocomplete/jquery.autocomplete.css” type=”text/css” />
<script type=”text/javascript” src=”http://dev.jquery.com/view/trunk/plugins/autocomplete/lib/jquery.bgiframe.min.js”></script>
<script type=”text/javascript” src=”http://dev.jquery.com/view/trunk/plugins/autocomplete/lib/jquery.dimensions.js”></script>
<script type=”text/javascript” src=”http://dev.jquery.com/view/trunk/plugins/autocomplete/jquery.autocomplete.js”></script>
<script>
$(document).ready(function(){
var data = “092 610 343 505 Utilities”.split(” “);
$(“#example”).autocomplete(data);
});
var data = [ {text:’Link A’, url:’/page2′}, {text:’Link B’, url: ‘/page2’} ];
$(“…”).autocomplete(data, {
formatItem: function(item) {
return item.text;
}
}).result(function(event, item) {
location.href = item.url;
});
</script>

</head>
<body>
Number: <input id=”example” /><p></p>
</body>
</html>[/CODE]

Can someone help me complete this code? For example, how can I change the code so that a text entry of “092” opens “www.google.com” when I hit enter after text entry?

Your help with this is greatly appreciated
Glen

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @glengates spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...