PHP Bootstrap - dynamic autocomplete tag input using jquery plugin

PHP Bootstrap - dynamic autocomplete tag input using jquery plugin

In this tutorial, I will tell you how to implement multiple input tags with dynamic data from MySQL database table using jquery plugin "tagmanager" and "typeahead" JS.

This is required in the application in which you need to show user selected options in a text area in tags with remove option.

This functionality can be done very easily by using jQuery "tagmanager" plugin for multiple input tags based on user selection from dynamic list of data.

Using Tag Manager plugin you can manage input tags separately from each input with better layout.

There are so many plugin available for multiple input tags but Tag Manager plugin can be easily implemented into application with different tag styles.

You can trigger the events to get notification when things happen. For example, when you are going to push the new tags or you have pushed a new tag and also when you remove any tag then you can hook on these events.

To use tag manager you need to have following libraries :

  • bootstrap.min.css
  • tagmanager.min.css
  • jquery.min.js
  • bootstrap.min.js
  • tagmanager.min.js
  • bootstrap3-typeahead.min.js

For this example, I have a database table with all countries :


Now create a "index.php" file for testing :


  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title>PHP Bootstrap - dynamic autocomplete tag input using jquery tag manager plugin </title>
  5.     <link rel="stylesheet" type="text/css" href="">
  6.     <link rel="stylesheet" type="text/css" href="">
  7.     <script type="text/javascript" src=""></script>
  8.     <script type="text/javascript" src=""></script>
  9.     <script type="text/javascript" src=""></script>
  10.     <script src=""></script>
  11. </head>
  12. <body>
  13. <div class="container">
  15.         <div class="form-group">
  16.             <label>Add Country Tags:</label>
  17.             <input type="text" name="countries" placeholder="Type here.." class="typeahead tm-input form-control tm-input-info"/>
  18.         </div>
  19. </div>
  20. <script type="text/javascript">
  21. $(document).ready(function() {
  22. var tags = $(".tm-input").tagsManager();
  23. jQuery(".typeahead").typeahead({
  24. source: function (query, process) {
  25. return $.get('aj.php', { query: query }, function (data) {
  26. data = $.parseJSON(data);
  27. return process(data);
  28. });
  29. },
  30. afterSelect :function (item){
  31. tags.tagsManager("pushTag", item);
  32. }
  33. });
  34. });
  35. </script>
  36. </body>
  37. </html>

  1. <?php
  3.     $mysqli = new mysqli("host", "username", "password", "database");
  4.     $sql = "SELECT name FROM countries
  5.             WHERE name LIKE '%".$_GET['query']."%'
  6.             LIMIT 10";
  7.     $result = $mysqli->query($sql);
  8.     $data = [];
  9.     while($row = $result->fetch_assoc()){
  10.      $data[] = $row['name'];
  11.     }
  12.     echo json_encode($data);
  13. ?>

Add Multiple Email addresses as tags in single text input Example

Phone: (+91) 8800417876
Noida, 201301
sakarya escort sakarya escort bayan sakarya escort serdivan escort sakarya escort sakarya escort serdivan escort
karasu escort akyazı escort serdivan escort akyazı escort ferizli escort sapanca escort serdivan escort söğütlü escort sakarya escort izmit escort arifiye escort erenler escort hendek escort kocaali escort pamukova escort taraklı escort geyve escort