Page is a not externally linkable
- Code, Content, and Presentation
-- JavaScript and AJAX
---- setTimeout to detect changes in a text field


Fotiman - 7:40 pm on Nov 28, 2012 (gmt 0)


Note, even if you have that if clause, it will still update every 10ms as long as the textarea has a value that is truthy (resolves to "true" when used as a boolean).

Instead, what you want to do is store the "last known value" of the textarea, and then test to see if the value is different. For example:


var lastValue = '';

function displayResult() {
if (textarea.value !== lastValue) {
lastValue = textarea.value;
iframe.open();
iframe.write(textarea.value);
iframe.close();
}
window.setTimeout(displayResult, 10);
}


Thread source:: http://www.webmasterworld.com/javascript/4523008.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com