Hi all,
I have used the Google API Autocomplete script (example below). Works great, however if a user types a value that isn’t specified in the script, I’d like a message to appear in the text box like ‘Not found’ or whatever.
<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() {
var data = [
{label: 'Ashford', value: 'http://www.ashford.co.uk'},
{label: 'Aylesbury', value: 'http://www.aylesbury.co.uk'},
];
$("input#autocomplete").autocomplete({
source: data,
focus: function (event, ui) {
$(event.target).val(ui.item.label);
return false;
},
select: function (event, ui) {
$(event.target).val(ui.item.label);
window.location = ui.item.value;
return false;
}
});
});
</script>
Many thanks for any advice.
Cheers