Boostrap Auto Suggestion

In this code we will do three things:

  1. We will  make Ajax call to get suggestion remotely
  2. Place the Suggestion in input box
  3. After that It will  call a remote ajax call to get the relevant data for the particular suggestion

HTML FORM

 <input id="cc_pay_to_name" class="typeahead form-control" step="any" type="text" placeholder="Enter Full Legal Name" />

JAVASCRIPT

$('input.typeahead').typeahead({
minLength: 3,
source: function (query, process) {
return $.get('check.php?action=getPayeeNameSuggestion', { query: query }, function (data) {
console.log(data);
data = $.parseJSON(data);

return process(data);
});
},
updater: function (data) {
console.log(data);
getPayeeInformation(data.id);
//alert(JSON.parse(data).id);
//return JSON.parse(data).name;
}

});

function getPayeeInformation(id)
{
$.getJSON(“action.php?action=getPayeeInformation&payee_id=” + id, function (data) {
$(“#cc_pay_to_name”).val(data.name);
$(“#cc_address_1”).val(data.address_1);
$(“#cc_address_2”).val(data.address_2);
$(“#cc_city”).val(data.city);
$(“#cc_state”).val(data.state);
$(“#cc_zip”).val(data.zip);

});
}

Advertisements