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

146
Vistas
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 Respuestas
Responde la pregunta

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 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