Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

119
Views
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 answers
Answer question

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 Report

0

You can try

const areaCodeNumber = Number(e.target.value)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!