I'm designing an html table with Jquery which only edits the records or just cancels when editing, which starts my problem here. Simply wish is that by pressing the cancel button return the data to as they were before, for example:
In my table delete the surname "Sanchez" by accident. Then I just press the cancel button and return the name "Sanchez" in my record as if it had not been edited.
On my "Cancel" button, just execute the input disabled in "true", nothing else, as I have no idea how to return the data that was edited by accident.
I show you my code so you can help me:
$("#Editar1").click(function(){
$("#nombre1").prop("disabled", false);
$("#apellido1").prop("disabled", false);
});
$("#Cancelar1").click(function(){
$("#nombre1").prop("disabled", true);
$("#apellido1").prop("disabled", true);
});
$("#Editar2").click(function(){
$("#nombre2").prop("disabled", false);
$("#apellido2").prop("disabled", false);
});
$("#Cancelar2").click(function(){
$("#nombre2").prop("disabled", true);
$("#apellido2").prop("disabled", true);
});
$("#Editar3").click(function(){
$("#nombre3").prop("disabled", false);
$("#apellido3").prop("disabled", false);
});
$("#Cancelar3").click(function(){
$("#nombre3").prop("disabled", true);
$("#apellido3").prop("disabled", true);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table border=1 >
<thead>
<tr>
<th>Id</th><th>Col 2</th><th>Col 3</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td><input id="nombre1" disabled value="Juan"></td>
<td><input id="apellido1" disabled value="sanchez"></td>
<td><button id="Editar1">Editar</button></td>
<td><button id="Cancelar1">Cancelar</button></td>
</tr>
<tr>
<td>2</td><td><input id="nombre2" disabled value="Joanna"></td><td><input id="apellido2" disabled value="herrera"></td>
<td><button id="Editar2">Editar</button></td>
<td><button id="Cancelar2">Cancelar</button></td>
</tr>
<tr>
<td>3</td><td><input id="nombre3" disabled value="Marcos"></td><td><input id="apellido3" disabled value="lopez"></td>
<td><button id="Editar3">Editar</button></td>
<td><button id="Cancelar3">Cancelar</button></td>
</tr>
</tbody>
</table>
I hope you can help me, thanks.