$('#ddos' + itr).select2({
//   width: '240px',
    allowClear: true,
    formatNoMatches: function (term) {
        /* customize the no matches output */
        var thisId = $(this).attr("id");
        // var itr = $(this).attr("data-itr");
        return "<input class='form-control' id='newddosSelectTerm' value='" + term + "'><a href='#' id='addNewddosSelect' data-id='" + thisId + "' class='btn blue custombtnstyle'>ADD</a>"
    }
}).parent().find('.select2-with-searchbox').on('click', '#addNewddosSelect', function () {
    /* add the new term */
    var ddosSelect = $('#newddosSelectTerm').val();
    var thisId = $(this).attr("data-id");
    $.post(hosturl + "/controllers/patienthistory.php?ac=addRow", {value: ddosSelect, table: 'drugDos'}, function (data) {

        $('.ddosSelect > .deleteoptincompo').before('<option value="' + ddosSelect + '" >' + ddosSelect + '</option>');
        $('#' + thisId + '').select2('val', ddosSelect).trigger("change"); // select the new term
        $('.ddosSelect').select2('close'); // close the dropdown 
    });
});