• info@bizmate.biz

How to set cursor position to the end of a text field

How to set cursor position to the end of a text field

Problem 

If you set focus on a form text field on your website you can end up with a curson position at the beginning of the word/value specified in the field. This article tells you how to apply a workaround to this accessibility problem.

Solution

There is a very small trick you can use to  show the cursor after the value specified in your text field. It consists indefining the value of the text field after focusing on it.
For instance:

document.getElementById("nameField").focus();
document.getElementById("nameField").value = "Bizmate.biz";
 

As a result you get the cursor to show after the "Bizmate.biz" value in your form text field called "nameField". I have tested this solution in Firefox and Internet Explorer successfully. On Opera this trick is still not working. Please let me know if you find a solution on Opera.

Bizmate