Overview: I have an HTML form that contains 10 radio buttons and 3 text areas with the following 3 buttons:
Enable Editing: The form input fields are disabled in this case (form fields are enabled/disabled depending on status). This button will enable input fields and will allow changes to be made to the form.
Save: save data to DB.
Cancel: This should "Discard changes" made to the form and restores the original values.
Note: The form gets populated from the DB. On "cancel" click I would like to restore the old data if any changes were made.
Issue: How can I implement an onclick method that will store data temporarily when "enable editing" button is clicked and another method that would restore the old form data(discard changes) when the "Cancel" button is clicked ?
What I have tried so far after looking at a similar question:
$(document).ready(function() {
$('#evaluationFormEdit').click(function() {
$('#evaluationForm').find(':input').each(function(i, elem) {
var input = $(elem);
input.data('initialState', input.val());
});
});
function restore() {
$('#evaluationForm').find(':input').each(function(i, elem) {
var input = $(elem);
input.val(input.data('initialState'));
});
}
$('#evaluationFormEditCancel').click(function() {
restore();
});
});