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

128
Vistas
I'm confusing getting value from <select> tag

I'm trying to get a value from <select> <option> tag. Select tag is like this

<select name="pref" className="XXXX" onChange={getValue}>
{areaData.map((area, index) => (
  <option key={index} value={area.areaCode}>XXXXX</option>
))}
</select>

I gave a number here in value={area.areaCode}

Then, getting value function is like this

  const getValue = function (e: any) {
    const areaCodeString = e.target.value
    const areaCodeNumber = e.target.valueAsNumber
    console.log(areaCodeString);
    console.log(areaCodeNumber);
  }

but Output said areaCodeString is "1" (string) and areaCodeNumber is "undefined" I want to get this value as number but it doesn't work. How can I get the value as number? I thought e.target.valueAsNumber was only solution.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can simply parse it as Number.

const areaCodeNumber = Number(areaCodeString)

Alternatively, you can use parseInt or parseFloat.

Note: You don't have valueAsNumber property in e.target, that's why it gives you undefined.

Refer: https://stackoverflow.com/a/12813049/11566161

https://cullenwebservices.com/javascript-numbers-number-parseint-parsefloat/

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can try

const areaCodeNumber = Number(e.target.value)
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