Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

161
Vistas
how to update dropdown list by clicking the update button in react

I want to give some text in input field and after clicking the update button it should be update in the dropdown list but its not working

import React from "react";
export default function DropDown() {
  const [input, setInput] = React.useState('');
  const selectproject=({e})=>{
    setInput(e.target.value);
  }
return (
    <>
    <select>
     <option>{input?input:'null'}</option>
    </select>
    <br/><br/>
      <input value={input} /><button onClick={selectproject}>Update</button>
    </>
  );
}
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

remove curly braces on selectproject props.

selectproject=(e)=>{
    setInput(e.target.value);
  }

you are destructuring e in <Event> which is not available. if you want to destructuring it, try this instead

selectproject=({target: {value}})=>{
     setInput(value);
   }

if you want dropdown list to be updated after clicking button, you'll need another state

import React from "react";
export default function DropDown() {
  const [input, setInput] = React.useState("");
  const [project, setProject] = React.useState("");
  const selectproject = () => {
    setProject(input);
  };
  const handleOnChange = (e) => {
    setInput(e.value.target);
  };
  return (
    <>
      <select>
        <option>{project ? project : "null"}</option>
      </select>
      <br />
      <br />
      <input value={input} onChange={handleOnChange} />
      <button onClick={selectproject}>Update</button>
    </>
  );
}

about 4 years ago · Juan Pablo Isaza Denunciar

0

Need to remove curly brace around e and set onchange to input:

import React from "react";
export default function DropDown() {
  const [input, setInput] = React.useState("");
  const selectproject = (e) => {
    setInput(e.target.value);
  };
  return (
    <>
      <select>
        <option>{input ? input : "null"}</option>
      </select>
      <br />
      <br />
      <input value={input} onChange={selectproject} />
      <button onClick= {selectproject}>Update</button>
    </>
  );
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use from two useState:

import React from "react";
function DropDown() {
    const [input, setInput] = React.useState('');
    const [select,setSelect] = React.useState('');

    const selectproject = () => {
        setSelect(input);
    }

    const handleChange = (e) => {
        setInput(e.target.value);
    }
    return (
        <>
            <select>
                <option>{select?select:'null'}</option>
            </select>
            <br/><br/>
            <input onChange={handleChange} value={input} /><button onClick={selectproject}>Update</button>
        </>
    );
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda