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

146
Views
how to put input box cursor at end of text

I want to add a number in input field on button click and set the cursor position at the end of text. this should happen every time when the button is clicked.

<input id="input"></input>
<button onclick="addnumber()">add</button>
addnumber(){

}
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

<input id="input"></input>
<button onclick="addnumber()">add</button>
    
<script>
    function addnumber() {
        const myInput = document.getElementById('input');
        const textLength = myInput.value.length;

        myInput.focus();
        myInput.setSelectionRange(textLength, textLength);
    }
</script>
about 4 years ago · Juan Pablo Isaza Report

0

let input = document.getElementById('input')
function addnumber() {
  input.value=69
  input.focus()
}
<input id="input">
<button onclick="addnumber()">add</button>

about 4 years ago · Juan Pablo Isaza Report

0

JS code :

let input = document.getElementById('input')
function addnumber() {
  input.focus(); 
  var val = this.input.value; 
  input.value = ''; 
  input.value = val;
}

HTML code:

  <input id="input">
  <button onclick="addnumber()">add</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!