вам нужно удалить значение из вашего массива, а также при удалении строки элемента из таблицы. Вот фиксированный код, пожалуйста, проверьте и дайте мне знать, если вам нужна помощь. вы просто добавляете слишком много скрипта, который не требуется.
// Exiscisting supplier dropdown change function - for new method
$("table.order-list").on("click", ".ibtnDel", function(_event) {
var $row = $(this).closest("tr"); // Find the row
var listVal = $row.find(".newStyle2").val();
delete temp[temp.indexOf(listVal)];
$(this).closest("tr").remove();
});
$("#excist_supp").on("change", function() {
if (!check()) {
$(".indexDrop").hide();
var newText = $("#excist_supp option:selected").text();
var newValue = $("#excist_supp option:selected").val();
$("#letterTable tbody").append('<tr><td><input type="text" id="sm_supp" value="' + newText + '" class="form-control newStyle1" name="sm_supp"></td><td><input type="text" id="sm_code" value="' + newValue + '" class="form-control newStyle2" name="sm_code"></td><td><button type="button" class="adRow ibtnDel newExcist" style="width:30%;position: relative;right: 25%; margin-bottom:0px">x</button></a></td></tr>');
$("#letterTable tr").each(function(i) {
var count = (i) - 1;
if (i === 0) return;
var input1 = $(this).find('.newStyle1');
var input2 = $(this).find('.newStyle2');
input1.eq(0).attr("id", "sm_supp" + count); // Text fields
input2.eq(0).attr("id", "sm_code" + count);
input1.eq(0).attr("name", "reqpartys[" + count + "].pname"); // Text fields
input2.eq(0).attr("name", "reqpartys[" + count + "].pacd");
});
}
});
/* compare two fields and not allow to selected options to select second time */
var temp = [];
function check() {
var listVal = $('#excist_supp').val();
var tableVal = $('.newStyle2').val();
var nawTab = JSON.stringify(tableVal);
if (temp.includes(listVal)) {
alert('matching!');
$(".notify").addClass("active");
$("#notifyType").addClass("failure");
setTimeout(function() {
$(".notify").removeClass("active");
$("#notifyType").removeClass("failure");
}, 3000);
return true;
} else {
// alert('Not matching!');
temp.push(listVal)
return false;
}
}
.letterSub {
position: relative;
top: 25px;
}
.order-scroll table.order-scroll {
width: 100%;
/* border-collapse: collapse; */
border-spacing: 0;
}
/* To display the block as level element */
table.order-scroll tbody,
table.order-scroll thead {
display: block;
}
table.order-scroll tbody {
/* Set the height of table body */
height: 130px;
/* Set vertical scroll */
overflow-y: auto;
/* Hide the horizontal scroll */
overflow-x: hidden;
}
.listbox {
background: white;
background: -webkit-linear-gradient(#ccc, white);
background: -o-linear-gradient(#ccc, white);
background: -moz-linear-gradient(#ccc, white);
background: linear-gradient(#fff, white);
border: 1px solid #ced4da;
overflow: auto;
}
.listbox option {
list-style: none;
margin: 0;
padding: 0;
}
.listbox option {
padding: 5px;
cursor: pointer;
}
.listbox option:hover {
background-color: #bbb;
}
.listbox option.active {
background: rgb(77, 176, 82);
}
option {
-webkit-transition: background-color 200ms linear;
-moz-transition: background-color 200ms linear;
-o-transition: background-color 200ms linear;
-ms-transition: background-color 200ms linear;
transition: background-color 200ms linear;
}
.listbox::-webkit-scrollbar {
width: 8px;
border: 1px solid #ced4da;
}
.listbox::-webkit-scrollbar-track {
background: rgba(0, 0, 0, 0.1);
}
.listbox::-webkit-scrollbar-thumb {
background: gray;
}
#excist_supp {
height: 440px;
width: 100%;
margin: 10px;
text-align: center;
margin-bottom: 0px;
}
.selector {
position: relative;
margin-bottom: 0px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<div class="col-sm-6">
<div class="col-12">
<div class="row">
<div class="col-12">
<div class="selector">
<select class="col-12 listbox newBox" name="List_0" size="20" id="excist_supp" style="height: 125px !important;">
<option class="indexDrop">Choose Existing Suppliers</option>
<option value="0000">Komal </option>
<option value="0001">Ranjeet</option>
<option value="0002">Vishal </option>
<option value="0003">Gaurav</option>
<option value="0004">Dhanpat</option>
<option value="0005">Joe</option>
<option value="0006">Gowri</option>
<option value="0007">shankar</option>
<option value="0008">Dhanpat</option>
</select>
</div>
</div>
</div>
</div>
</div>
<!-- Small table -->
<div class="col-5">
<div class="container">
<div class="row clearfix">
<div class="table-wrapper">
<div class="table-scroll">
<table id="letterTable" class="table table-bordered table-striped order-scroll order-list">
<thead>
<tr style="background-color: #680f79;color: #fff;">
<th class="text-center">Supplier Name</th>
<th class="text-center">Supplier Code</th>
<th class="text-center">Action</th>
</tr>
</thead>
<tbody id="mytbody" style="text-align: center;">
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>