I have a text input. A value is populated into it when the page loads. If the user changes anything in text box, then I want to get the changed value (the new value) and old value. But calling ELEMENT.value it only returns the changed/new value.
How do I get the old value?
Here is my code:
<head>
<script type="text/javascript">
function onChangeTest(changeVal) {
alert("Value is " + changeVal.value);
}
</script>
</head>
<body>
<form>
<div>
<input type="text" id="test" value ="ABS" onchange="onChangeTest(this)">
</div>
</form>
</body>
element.defaultValuewill give you the original value.Please note that this only works on the initial value.
If you are needing this to persist the “old” value every time it changes, an expando property or similar method will meet your needs