select2 example – Jquery Select2 – Select box with search example code

select2 example – Jquery Select2 – Select box with search example code Explain Chosen and Select2 with examples. Select2 is a jQuery-based replacement for select boxes.

select2 example – Dynamic option creation

It supports searching, remote data sets, and pagination of results. Select2 plugin is used to customize HTML select element.

select 2 dropdown

  maximumSelectionLength: 2

Select2 dropdown example


<html lang="en">
    <title>Jquery Select2 - Select Box with Search Option -</title>  
    <script src=""></script>
	<link href="" rel="stylesheet" />
	<script src=""></script>

<div style="width:520px;margin:0px auto;margin-top:30px;height:500px;">

  <h2>Select Box with Search Option Jquery Select2.js - Example</h2>
  <select class="getarticle" style="width:500px;">
	  <option>PAKAINFO ACL</option>
	  <option>PAKAINFO PDF</option>
	  <option>PAKAINFO Helper</option>
	  <option>PAKAINFO API</option>
	  <option>PAKAINFO CRUD</option>
	  <option>PAKAINFO Angural JS Crud</option>
<script type="text/javascript">

add image in select2 dropdown

    templateResult: formatcategory,
    templateSelection: formatcategory

function formatcategory (fldt) {
    if (! {
        return fldt.text.toUpperCase();

    var fldtimage = $(fldt.element).attr('data-image'); 
       return fldt.text.toUpperCase();
    } else {                    
        var $fldt = $(
           '<span><img src="' + fldtimage + '" width="80px" /> ' + fldt.text.toUpperCase() + '</span>'
        return $fldt;

select2 replace options

var showDataDropDown = function () {
    var details = [];
    var selectedplayer = $("#players").val();
    $.each(pageData.products[selectedplayer].qty, function (key, value) {
            text: value,
            id: key
        data: details


Don’t Miss : Jquery Select2 Ajax Autocomplete Example With Demo In PHP Codeigniter Example

I hope you get an idea about select2 example.
I would like to have feedback on my
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.