Quiero agregar un número en el campo de entrada al hacer clic en el botón y establecer la posición del cursor al final del texto. esto debería suceder cada vez que se hace clic en el botón.
<input id="input"></input> <button onclick="addnumber()">add</button> addnumber(){ }<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> let input = document.getElementById('input') function addnumber() { input.value=69 input.focus() } <input id="input"> <button onclick="addnumber()">add</button>Código JS:
let input = document.getElementById('input') function addnumber() { input.focus(); var val = this.input.value; input.value = ''; input.value = val; }Código HTML:
<input id="input"> <button onclick="addnumber()">add</button>