/ Published in: PHP
codeigniter autocomplete
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
$(document).ready(function () { $("#country").keyup(function () { $.ajax({ type: "POST", url: "http://localhost/autocomplete/autocomplete/GetCountryName", data: { keyword: $("#country").val() }, dataType: "json", success: function (data) { if (data.length > 0) { $('#country').attr("data-toggle", "dropdown"); $('#DropdownCountry').dropdown('toggle'); } else if (data.length == 0) { $('#country').attr("data-toggle", ""); } if (data.length >= 0) $('#DropdownCountry').append('<li role="presentation" ><a role="menuitem dropdownnameli" class="dropdownlivalue">' + value['name'] + '</a></li>'); }); } }); }); $('ul.txtcountry').on('click', 'li a', function () { $('#country').val($(this).text()); }); });