trying learn jquery implement autosave feature , need assistance. have code monitor status of form fields see if there has been change. works, need monitor changes in specific form, not form inputs on page. there search box , newsletter form on same page , when these form fields changed, detected well, need filter out somehow or better yet, target specific form.
$(function(){ setinterval("checkdirty()",10000); $(':input').each(function() { $(this).data('formvalues', $(this).val()); }); }); function checkdirty() { var isdirty = false; $(':input').each(function () { if($(this).data('formvalues') != $(this).val()) { isdirty = true; } }); if(isdirty == true){ alert("isdirty=" + isdirty); } }
just add class form , use filter
$('.form :input').each(function() { $(this).data('formvalues', $(this).val()); });
edit
just suggestion, can attach change event directly form
live demo here : http://jsfiddle.net/jomanlk/knx8p/1/
<form> <p><input type='text'></p> <p><input type='text'></p> <p><input type='checkbox'></p> </form> <p><input type='text'></p> <div id='log'></div> $('form :input').change(function(){ $('#log').prepend('<p>form changed</p>') });
you can improve adding timer , making save every xx seconds.
Comments
Post a Comment