Good day, I have a form with six text fields in which the user types information and by pressing the submit button these are dynamically added an HTML table, I only show them in the table, there is no income in the database, that's what I use afterwards and for the moment everything works fine, this is the code of the form and the table
<div class="form-group">
<input type="text" id="inputText1" required>
<input type="text" id="inputText2" required>
<input type="text" id="inputText3" required>
<input type="text" id="inputText4" required>
<input type="text" id="inputText5" required>
<input type="text" id="inputText6" required>
</div>
<button type="button" class="btn btn-default" id="submit">Submit</button>
<button type="button" class="btn btn-default" id="actualizar">Actualizar</button>
<br /><br />
<div class="table-responsive">
<table class="table table-striped table-bordered table-condensed" id="myTable" style="width:90%; margin:0 auto;">
<thead>
<tr>
<th>ID</th>
<th>Last Name</th>
<th>Username</th>
<th>Nivel</th>
<th>DUI</th>
<th>ISSS</th>
<th></th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
- Update HTML table row data
But now comes the part of updating any row of the table -by request- a select button has been added to each row of the table which when pressed places the information of each column of the selected row in the text field corresponding with this code:
$(document).ready(function () {
$("#myTable").on('click', '#select', function (e) {
e.preventDefault();
var currentRow = $(this).closest("tr");
var col1 = currentRow.find("td:eq(0)").text();
var col2 = currentRow.find("td:eq(1)").text();
var col3 = currentRow.find("td:eq(2)").text();
var col4 = currentRow.find("td:eq(3)").text();
var col5 = currentRow.find("td:eq(4)").text();
var col6 = currentRow.find("td:eq(5)").text();
$("#inputText1").val(col1);
$("#inputText2").val(col2);
$("#inputText3").val(col3);
$("#inputText4").val(col4);
$("#inputText5").val(col5);
$("#inputText6").val(col6);
$(this).closest('tr').remove();
});
});
and if you show me the information in the text fields, the problem is that I do not know how to update the information of exactly the selected row, at the moment what I do is:
but I would like it not to disappear from the table, I would like the text fields to be populated but that the row remains in the table and that at the time of updating the corresponding row is updated
how could I achieve it?
I remind you that these operations do not represent any connection to the database, thanks for the help.
the table the charge taking the values of the inputs and then making an append on the table and then clean the values of each input, as follows:
var dui = $("#inputText1").val();
var lastname = $("#inputText2").val();
var name = $("#inputText3").val();
var country = $("#inputText4").val();
var DUI = $("#inputText5").val();
var ISSS = $("#inputText6").val();
$('#myTable tbody').append('<tr><td for="dui">' + dui + '</td><td for="lastname">' + lastname + '</td><td for="name">' + name + '</td><td>' + country + '</td><td for="DUI">' + DUI + '</td><td for="ISSS">' + ISSS + '</td><td><a href="#" id="select">Modificar</a></td></tr>');
$("#inputText1").val('');
$("#inputText2").val('');
$("#inputText3").val('');
$("#inputText4").val('');
$("#inputText5").val('');
$("#inputText6").val('');
$('#inputText1').focus();