0

Is there a way to extract the value of an input tag prior to input change at the onchange event? Or is there an event triggered before 'change' instead? In particular I need it for type range. Thanks

This question adds to previously asked similar questions because I also ask if there is NO way to 'catch' the value before it is being changed as in many other programming languages.

 <form >
  <input type="range" value="0" id="indentA" name="indentA" min="-20" max="20" onchange="alert('trying to output original value here... \ncurrent value is: '+this.value);" >
 </form>
Israel Gav
  • 373
  • 4
  • 16
  • Possible duplicate http://stackoverflow.com/questions/1909992/how-to-get-old-value-with-onchange-event-in-text-box – ahpan Jul 10 '15 at 15:39
  • possible duplicate of [Getting value of select (dropdown) before change](http://stackoverflow.com/questions/4076770/getting-value-of-select-dropdown-before-change) – Mike Brant Jul 10 '15 at 15:49
  • Please see edited question to see the difference – Israel Gav Jul 10 '15 at 16:31

1 Answers1

1

Is this the one you are looking? I am capturing the old value when the slider changes. Please have a look at the below code snippet.

Code Snippet

var previos_value=0;
function getValue(value){
  
  alert('current value is: '+value);
  alert('Previous value is: '+previos_value);
  
  
  previos_value=value;
  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>
<form >
  <input type="range" value="0" id="indentA" name="indentA" min="-20" max="20" onchange="getValue(this.value)" >
 </form>
Jayababu
  • 1,581
  • 11
  • 25