I have a table to which, I add data from three different TextBox . For this I use jQuery and C # as follows:
<form>
<input type="text" id="inputText1">
<input type="text" id="inputText2">
<input type="text" id="inputText3">
<button type="button" class="btn btn-default" id="submit">Submit</button>
</form>
<script>
$("#submit").click(function (e) {
e.preventDefault();
var val1 = $("#inputText1").val();
var val2 = $("#inputText2").val();
var val3 = $("#inputText3").val();
$('#myTable').append('<tr><th scope="row">2</th><td class="value">' + val1 + '</td><td>' + val2 + '</td><td>' + val3 + '</td><td><a href="#" id="select">Modificar</a> <a href="#" id="eliminar">Eliminar</a></td></tr>');
$("#inputText1").val('');
$("#inputText2").val('');
$("#inputText3").val('');
});
</script>
The code of my table is as follows (pure HTML ).
<div class="table-responsive">
<table class="table table-striped table-bordered table-condensed" id="myTable" style="width:90%; margin:0 auto;">
<thead>
<tr>
<th>#</th>
<th>ID</th>
<th>Last Name</th>
<th>Username</th>
<th></th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
It's very simple and as you can see, it has three columns, but the one that interests me is the ID , this should not be repeated in any record of the table, I want to achieve it, using jQuery , that at the moment of entering a repeated ID a message is shown to the user indicating the impossibility of registering the employee and that in fact he / she is not allowed to enter the record in the table.
As a complement, this data is stored in the table, but not in the database, that will be a later step. For now, I just want to validate that the ID is not repeated in the table records.