i have little dashboard in html+jquery mobile contains number of buttons, sliders, checkboxes, number inputs, etc.
obviously want connect actions (changes fields etc) calls backend. however, if pushes switch button 3 times in row qucikly don't want trigger 3 backend calls button clicks have hardware consequences.
what want each of these buttons/sliders/checkboxes trigger backend calls after x second delay (when consider user has decided entered number, slider or checkbox has value want).
what elegant way of achieving this?
if want x second delay after user stops entering data, use set time out , update function. will, of course, cause user experience lag.
var seconds = 3, timer; $(function(){ var update = function(){ $("#response").append("<p>run updates!</p>"); } $("#slider-1").change(function(){ if(timer) cleartimeout(timer); timer = settimeout(update, seconds * 1000); }); });
here's jsfiddle http://jsfiddle.net/aeftd/4/
Comments
Post a Comment