$(".semen_epith_cells").select2({
    width: '240px',
    allowClear: true,
    formatNoMatches: function (term) {
        /* customize the no matches output */
        var elemId = $(this).attr("id");
        var id = $(this).attr("data-id");
        return "<input class='form-control' id='newsemen_epith_cellsTerm' value='" + term + "'>\n\
                               <a href='#' id='addNewsemen_epith_cellsRow' data-elemId='" + elemId + "'  data-id='" + id + "'   \n\
                                  class='btn blue custombtnstyle'>ADD</a>"
    }
}).parent().find('.select2-with-searchbox').on('click', '#addNewsemen_epith_cellsRow', function () {
    /* add the new term */
    var newTerm = $('#newsemen_epith_cellsTerm').val();
    var id = $(this).attr("data-id");
    var elemId = $(this).attr("data-elemId");
    $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
        selectId: 'semen_epith_cells', new_name: newTerm, id: id,
        tableName: $('#' + elemId + '').attr('data-tableName'),
        colName: $('#' + elemId + '').attr('data-tableName')
    }, function (data) {

        $('.semen_epith_cells > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + newTerm + '</option>');
        $('#' + elemId + '').select2('val', Number(data)); // select the new term
        $('.semen_epith_cells').select2('close'); // close the dropdown
    });
});