How to get previous value of <select> in React?

how to get old value of textbox in javascript
how to get old value of textbox in jquery
how to compare old and new values in javascript
javascript input onchange get value
how to store previous value in javascript
javascript select onchange get value
react onchange get previous value
html select old value

An example.

red is selected from the very start.

Then I select green. That is, from red to green.

I can get new value green in event.currentTarget.value. But how do I get previous red?

<select className="foo" onChange={this.onSectChange} value="red">
    <option value="no color">No Color</option>
    <option value="red">Red</option>  // this one is selected
    <option value="green">Green</option> // this one I will select
    <option value="blue">Blue</option>

onSectChange = (event) => {

    let prevVal = event.??? // How to get a previous value, that is Red
    let newVal = event.currentTarget.value; // Green - is a new value just selected, not previous


I mean, does React provide this functionality out-of-the-box along with their SyntheticEvent creation? Or do I still have to hack to get it?

You can use React's controlled components to achieve this. The state will have the previous value.

<script src=""></script>
<script src=""></script>
<script src=""></script>
<div id="app"></div>

<script type="text/babel">
class Select extends React.Component {
    this.state = {
      select: 'red',
    this.onSectChange = this.onSectChange.bind(this)
  onSectChange(e) {
    var newVal =
    console.log(, newVal)
      select: newVal,
  render() {
    return <select className="foo" onChange={this.onSectChange} value={}>
    <option value="no color">No Color</option>
    <option value="red">Red</option>  // this one is selected
    <option value="green">Green</option> // this one I will select
    <option value="blue">Blue</option>

ReactDOM.render(<Select/>, document.getElementById('app'))

2. If change (ie. 5 to 8), the function will be executed and get previous value (5) I cannot figure out how to get change event work in these cases. Jack Smith  Re: Get Previous Values Thank you everyone for your reponses, but all the solutions provided are not working. I have tried this solution, to get Previous Data in a separate table and join it to my original table using a new generated key and playing with the quarter number.

currentTarget is a property supported by browsers and it doesn't have anything to do with React, in itself.

SyntheticEvent is just a wrapper around the browser's native event, which exposes certain browser events.

The closest thing to what you're trying to do that comes to mind is Event.originalTarget, but it's an experimental feature only implemented in Mozilla.

So, to answer your question: no, React doesn't provide that functionality out of the box. And I wouldn't say you need a hack to get the previous value of your dropdown menu.

For instance, you could use componentWillReceiveProps and compare nextProps with this.props.

Please provide more details, if I misunderstood your question.

Hello, I have a problem getting the previous/old value of the select element on the change (or event. What would be the way  What I want to do is, getting the previous row value as shown below. There are multiple "MagazaKodu" and "FaturaSaati". I want to get previous values according to both "MagazaKodu" and "FaturaSaati". How can I handle this? I have tried "EARLIER" function but it did not work.

Use what we call a "controlled" input. Here's a good explanation of the concept of controlled and uncontrolled inputs.

In your case:

Set your initial state in the constructor

constructor(props) {

    this.state = {dropdownValue: 'red'};

Set the value of your select input as the value stored in your state

<select className="foo" onChange={this.onSectChange} value={this.state.dropdownValue}>

Then in your onChange event handling function you can get the previous value as it's still stored in state, before overwriting it with the new value from the event

onSectChange = (event) => {
    // You haven't yet updated the state, so you still have access to the old value.
    let prevVal = this.state.dropdownValue; 
    let newVal = event.currentTarget.value; 

    // You need to set the new value in your state so the component is
    // rerendered to show the new value as selected
    this.setState({dropdownValue: newVal});

Hello,. It is possible to get the previous value, but only before it was changed. As a workaround, you can use a Business Rule triggered before updating a user. Get the Next and Previous Row Value in SQL Server. This post can help you to get the next and previous row Value in SQL Server using T-SQL. We had a requirement to get the previous row information and compare it with the current row value.

this is stored in:

I have many2one field and I have written onchange method on it. When onchange happens i want the previous value of it. How can it possible? It will keep all previous values in the right order. You may implement your own or use the java Collections one: Deque<Integer> stack = new ArrayDeque<Integer>(); Each time you set the variable, put it in the stack (either through setter or AOP as mentioned in the other answers). That way, you will be able to access al previous values.

use will return you the previously value selected

previous value of column-wise. To change it down the table, Right click on the created field and go to compute using and select table(down). Is there a way to get the previous value of an item after it was modified? I am working on a calendar and the user will input several values in the form such as Title, Schedule and so on. What I would like to do is get the previous value of those fields after it was modified.

Does anybody knows how to obtain the property's previous value, the value that was stored just before commit? Actually my purpose is to update  In Workflow settings --> Conditional Start option gives you the current and previous values of a column, here you can check current and previous values of a column/field and then decided whether to run the workflow or not when an item is edited (if you want to trigger the workflow on item change).

Re: how to get previous value of a list item in Nintex workflow? Hi,. In Workflow settings --> Conditional Start option gives you the current and previous values  One way to obtain a rank value for a given value in a row is to count the number of rows, in the same table, that have a value larger (or smaller) than the one that is being compared. This technique returns a blank or zero value for the highest value in the table, whereas equal values will have the same rank value and next value (after the equal values) will have a non consecutive rank value.

Formula field calculate value at runtime so it can't support your usecase but you can use following workaround. Create another field text type. Fill that field using  I would like to get the previous row value for a text column using DAX. Example: Text_column. A. B. C . Expected Output: Text_column, Previous_value. A NULL. B A. C B . Please let me know incase of any clarification. Thanks in Advance.