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

300
Vistas
HTML input - Replace selected value by typing

I have the below input that the user can first click to enable (button1), type the desired new value, and finally save it (button2).

<input class="form-control inputUserValue" onkeypress="return contoso.isNumberKey(this, event,3);"
data-default_value="10,00" value="10,00" disabled="">

The issue: after the field is enabled, the user has first to erase the input content with delete or backspace at keyboard (including when the content is already selected) and then start typing the new value at the blank input field. So, the user can't simply use the mouse to select and just type the new value. This behaviour also occurs at other sections of the software when the input is text.

The idea is to improve the user experience by making it possible to just type the desired new value after button1 pressed, replacing existing and displayed content. The existing text/value should still be displayed, but already selected and ready to be replaced if the user types, or the user may want to deselect and make same minor adjust at the existing text/value.

We've tried onclick="this.select();" when button1 pressed, but still we couldn't type the new value without delete or backspace first.

Can anyone help on how to achieve this?

The HTML is generated and managed with JS. The input is whitin a table-responsive. Our system is designed to work on Chrome.

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

0

You were on the right way to use the select() method, but you first need to focus() the input:

usrinput.focus();
usrinput.select();

Working example: (for input type text)

const usrinput = document.querySelector('input');
document.querySelector('#button1').addEventListener('click', function() {
  usrinput.disabled = false;
  usrinput.focus();
  usrinput.select();
});
<button id="button1">enable</button>
<input type="text" value="10,00" disabled>

<button id="button2">Save</button>


Working example: (for input type number)

const usrinput = document.querySelector('input');
document.querySelector('#button1').addEventListener('click', function() {
  usrinput.disabled = false;
  usrinput.focus();
  usrinput.select();
});
<button id="button1">enable</button>
<input type="number" value="10" disabled>

<button id="button2">Save</button>

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