How to get selected value from drop downlist in ReactJs?

31 views Asked by At

i am not able to get the value from drop list the value that i am getting are wrong, they are reverse if i click complete it will show incomplete in console and vice verse

const [status, setStatus] = useState("");
  const handleChange = (e) => {
    setStatus(e.target.value);
    console.log(status);

<select className="formList" onChange={handleChange}>
          <option value="incomplete">Incomplete</option>
          <option value="complete">Complete</option>
        </select>
  };

i am expecting to get correct values

1

There are 1 answers

1
SudhakaranV On

Try this

const [status,setStatus]=useState("");

const handleChange = (e) => {
setStatus(e.target.value);
};

useEffect(() => {
console.log(status);
}, [status]);

return (
<select className="formList" 
onChange={handleChange}>
<option value="incomplete">
Incomplete</option>
<option 
value="complete">Complete</option>
</select>
);