javascript - How to get the old value of a textarea -


that's it. how can old value of textarea in order compare new value?. current value becomes old value after triggering event (say, keyup event).

i have seen solutions, example, using cookies record old value , new value, however, such solution doesn't work in case because of type of manipulation want perform later.

hopefully, there suggestion works better that.

thanks in advance.

update:

after following suggestions @drachenstern, @matthew, @peter, ended this

var starttimer = null; var oldvalue; $("#textarea").keydown($.debounce( 1000, true, function(){ oldvalue = $("#textarea").val(); } ));  $("#textarea").keyup(function(){ if(starttimer) cleartimeout(starttimer); starttimer = settimeout(function(){ var newvalue = $("#textarea").val(); d = // here clever comparison oldvalue = newvalue; },2000); }) 

by way, $.debounce function jquery throttle / debounce plugin.

this want, however, i'd obtain variable d outside of settimeout function , of keyup function, in order use elsewhere. however, cleartimeout seems tricky when comes return values. way value of d?.

var oldvalue = document.getelementbyid("textareaid").value;  document.getelementbyid("textareaid").onchange = function(){   var newvalue = this.value;   //compare oldvalue , newvalue   oldvalue = newvalue; } 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -