The solution alternative I know not is only with HTML , it also uses JavaScript .
Unlike other solutions, you can manipulate the cursor without overwriting the value, using the setSelectionRange ( ) :
The métodoHTMLInputElement.setSelectionRange()
defines the positions
start and end of the current selection of the text in a <input>
element.
Example 1:
<form>
<div>
<input type="text" name="p" value="teste"
onfocus="this.selectionStart = this.selectionEnd = this.value.length;"
autofocus="true"/>
</div>
</form>
Example 2:
var campo = document.getElementById("p");
var tamanho = campo.value.length;
campo.setSelectionRange(tamanho, tamanho);
<form>
<div>
<input type="text" name="p" id="p" value="teste" autofocus="true"/>
</div>
</form>
Note:
Considering the possible number of digits in a <input />
, avoid assigning selectionEnd
a constant value unless you know maxlength
.