Codeigniter-autocomplete-customjs


/ Published in: PHP
Save to your folder(s)

codeigniter autocomplete


Copy this code and paste it in your HTML
  1. $(document).ready(function () {
  2. $("#country").keyup(function () {
  3. $.ajax({
  4. type: "POST",
  5. url: "http://localhost/autocomplete/autocomplete/GetCountryName",
  6. data: {
  7. keyword: $("#country").val()
  8. },
  9. dataType: "json",
  10. success: function (data) {
  11. if (data.length > 0) {
  12. $('#DropdownCountry').empty();
  13. $('#country').attr("data-toggle", "dropdown");
  14. $('#DropdownCountry').dropdown('toggle');
  15. }
  16. else if (data.length == 0) {
  17. $('#country').attr("data-toggle", "");
  18. }
  19. $.each(data, function (key,value) {
  20. if (data.length >= 0)
  21. $('#DropdownCountry').append('<li role="presentation" ><a role="menuitem dropdownnameli" class="dropdownlivalue">' + value['name'] + '</a></li>');
  22. });
  23. }
  24. });
  25. });
  26. $('ul.txtcountry').on('click', 'li a', function () {
  27. $('#country').val($(this).text());
  28. });
  29. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.