Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

291
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda