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

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

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