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

140
Views
The definitive way to append a unit to your number input

๐Ÿ‘‹ Hi community!

What would be the proper way to add a unit inside a number input?

The goal is not to add a span with a negative left margin to come over the input, but to really insert a non-editable unit directly after the number, adapting to the number length:

[....3โ‚ฌ....]
[...333โ‚ฌ...]
[..33333โ‚ฌ..]

I've found this calculator to achieve this result quite elegantly, but can't figure how to get the same effect.

Any ideas? ๐Ÿ™

about 4 years ago ยท Juan Pablo Isaza
1 answers
Answer question

0

First of all Don't use input of a type number for this one because it will not allow you to use currency symbol.

Now, create an input and listen for keypress. If it's a number or minus sign or a dot intert it before the symbol.

input.addEventListener('keypressed', event => {
  const codes = [] // check the codes here https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values
  if (codes.includes(event.key)) return
  input.value = input.value.slice(0, -1) + event.key // probably some mapping needed
})

The code above is an untested proof of concept

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!