I have two textboxes which has a default value of 25. I have 2 buttons; increment by 1 and decrement by 1. I do not want to manual key in the values of the textboxes, as such, I wanted to create a dropdown select to control the values of the textbox. This is how it looks like:
Is it possible to bind the textboxes with the select?
Additional Question:
Is it possible to have one [value,setValue] to control both inputs?
This is my code:
const { useState } = React;
function MyApp(){
const [value1, setValue1]= useState(25)
const [value2, setValue2]= useState(25)
function increment(){
if(selected_id == 1){ //not sure how to implement
setValue1(value1+1)
}
else{
setValue2(value2+1)
}
}
function decrement(){
if(selected_id == 1){ //not sure how to implement
setValue1(value1-1)
}
else{
setValue2(value2-1)
}
}
return(
<div id="react">
<div>
Textbox1: <input id="1" defaultValue="value1"/>
Textbox2: <input id="2" defaultValue="value2"/>
</div>
<div>
<select defaultValue="Textbox1"/>
<button onClick={increment}> Increment </button>
<button onClick={decrement}> Decrement </button>
</div>
</div>
)
}
ReactDOM.render(
<MyApp />,
document.body
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.13.0/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.13.0/umd/react-dom.production.min.js"></script>
