title: How to capture old value and set it back on cancel using javascript
body: <p>I have a text field from which I am calling a function on <code>onChange</code> event. I am throwing a confirm window here when the value in that textfield is changed. If cancel is clicked( in confirm window), the old value must get set back into the text field. If proceed or ok is clicked, the new value should be retained.
  I have been trying this for a long time but am unable to retain the old value.</p>
  
  <p>Eg:
  Before onchange, val in text field ='first';
  onChange event, val changed to 'second', confirm window opens, if ok selected text field should have second and if cancel is selected 'first' should be present in the text field.</p>
  
  <pre><code>function onChangeOfValue(input){
      //var oldValue = document.getElementById(input).value;
      document.getElementById(input).onchange = function(){
      var newValue = this.value;
      alert("newVal is---&gt;"+newValue);
      if(document.getElementById(input) != null &amp;&amp; document.getElementById(input) != '' 
      &amp;&amp; !confirm("Do you want to continue?")){
  
      // this.input=oldValue;
          return false;
      }
      }
  
  }
  </code></pre>