I want to create a JSON with only those input fields that are changed before submitting the form.
How can I keep each and every changed value in the form of JSON?
$(document).ready(function() {
$('#save').click(saveChangedValues);
}
function saveChangedValues(e) {
e.preventDefault();
var fields = $( "#frmStudInfo :input" ).serializeArray();
trackFormDataChanges(fields);
//make a ajax call with json only with the changed fields
$.ajax{(
)}
}
var finalJSON = {};
function trackFormDataChanges(fields){
$.each( fields, function( i, field ) {
//create final json
});
}
<form id="frmStudInfo">
Name <input type="text" id="name" name="name" >
Date <input type="date" id="bdate" name="bdate">
ID <input type="number" id="stdID" name="stdID">
<input type="submit" id="save" value="Save" />
<form>