I have followed this tutorial http://blattchat.com/2013/06/04/twitter-bootstrap-typeahead-js-with-underscore-js-tutorial/ and its working in my own project. I managed to set a hidden field with the id and submitting the form to another page.
How can the "local" array be replaced so that the array is retrieved from a mysql database.
I also tried http://www.codingforums.com/showthread.php?t=286412 but I did not get it to work with setting the hidden field.
=====================================================================
After trying some extra things I get the following working.
<div class="content">
<form method="post" name="quicksearchform" id="quicksearchform" action="">
<fieldset>
<input type="text" placeholder="Quick search" id="quicksearch" class="quicksearch">
<input type="hidden" id="quicksearchid" name="quicksearchid">
<input type="hidden" id="quicksearchtype" name="quicksearchtype">
</fieldset>
</form>
</div>
<script>
$(function($) {
$('.quicksearch').typeahead({
name: 'quicksearch',
valueKey: 'name',
local: [{"id":"1","name":"user1","type":"type1"},
{"id":"2","name":"user2","type":"type2"}
]
}).on('typeahead:selected', function(event, datum) {
$('#quicksearchid').val(datum.id);
$('#quicksearchtype').val(datum.type);
$('#quicksearchform').submit();
});
});
</script>
I have a php file that generates the same output as I have put after local:. So the only thing what has to be done is loading the data from the php file (which is json_encoded).