Sorry for my bad English, I don't understand javascript but I need a function. I try this code
<div class="well col-md-5">
<input id="demo2" type="text" class="col-md-12 form-control" placeholder="Search cities..." autocomplete="off" />
</div>
<div class="col-md-7">
<pre class="prettyprint">
</pre>
</div>
<script>
$(function() {
function displayResult(item) {
$('.alert').show().html('You selected <strong>' + item.value + '</strong>: <strong>' + item.text + '</strong>');
}
$('#demo2').typeahead({
source: [
{ID: 1, Name: 'Toronto'},
{ID: 2, Name: 'Montreal'},
{ID: 3, Name: 'New York'},
{ID: 4, Name: 'Buffalo'},
{ID: 5, Name: 'Boston'},
{ID: 6, Name: 'Columbus'},
{ID: 7, Name: 'Dallas'},
{ID: 8, Name: 'Vancouver'},
{ID: 9, Name: 'Seattle'},
{ID: 10, Name: 'Los Angeles'}
],
displayField: 'Name',
valueField: 'ID',
onSelect: displayResult
});
});
</script>
It works. But I have a file clients.php updated 2 times each day with this code
<?php
$client_listing ="
{ID: 1, Name: 'Toronto'},
{ID: 2, Name: 'Montreal'},
{ID: 3, Name: 'New York'},
{ID: 4, Name: 'Buffalo'},
{ID: 5, Name: 'Boston'},
{ID: 6, Name: 'Columbus'},
{ID: 7, Name: 'Dallas'},
{ID: 8, Name: 'Vancouver'},
{ID: 9, Name: 'Seattle'},
{ID: 10, Name: 'Los Angeles'}";
?>
I try to replace $client_listing to my first code but it doesn't work
<?php include('data/clients.php'); ?>
<script>
$(function() {
function displayResult(item) {
$('.alert').show().html('You selected <strong>' + item.value + '</strong>: <strong>' + item.text + '</strong>');
}
$('#demo2').typeahead({
source: [
<?php echo $client_listing; ?>
],
displayField: 'Name',
valueField: 'ID',
onSelect: displayResult
});
});
</script>
Thank you for the help
Didier