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

148
Vistas
How to get the values from <select multpile={true}> in ReactJs

I have a form that has a select-multiple field. It is just getting one value that is first clicked but not the other values that are clicked after clicking the first one. Hhow to get the values? Below is my code.

assignment of state, Here shift and board are the state to store the values of multi-select field

 const [formData, setFormData] = useState({
    name: "",
    photo: "",
    adhar: "",
    phone: "",
    location: "",
    fullAddress: "",
    age: "",
    gender: 0,
    schooName: "",
    experience: "",
    teachForNoDays: "",
    shift: [],
    subject: "",
    teachClass: "",
    board: [],
    homeTuition: false,
    fees: "",
    homeTuitionFees: "",
  });

onChange function

const changeFormData = (e) => {
    // this is how we do when to specifically define a type in the target
    const { name, type } = e.target;
    console.log(e.target.value);
    setFormData({
      ...formData,
      [name]: e.target[type === "checkbox" ? "checked" : "value"],
    });
  };

the fields, only putting up the shift one here

<select
   name="shift"
   id="shift"
   defaultValue={shift}
   size={2}
  onChange={(e) => changeFormData(e)}
   multiple={true}
  >
     <option value="Evening">Evening</option>
     <option value="Morning">Morning</option>
</select>
about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

<select> has an e.target.options field which is an array containing all the selected options.

You should take that into consideration in changeFormData().

Don't forget to properly "control" the value of your select component by assigning it with the current value:

<select
   ...
   value={formData.shift}
   multiple
  >
     ...
</select>
about 4 years ago · Santiago Trujillo 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