user1200540
user1200540

Reputation:

How can i set focus to specific index of the text in a text box?

When i call TextBoxNameHere.Focus() it sets focus BUT it highlights the contents of the text box

I need it to set the cursor to be at the last character so if someone presses a key after that it doesn't erase the content, I have searched through a great deal of questions, but most of them are just asking how to set focus which i already know =|

Upvotes: 2

Views: 2494

Answers (2)

Erik Nordenhök
Erik Nordenhök

Reputation: 655

Try this:

var value = TextBoxNameHere.val();
TextBoxNameHere.Focus();
TextBoxNameHere.val(value);

As in, reset the value after giving focus

Upvotes: 0

kaj
kaj

Reputation: 5251

You can usually do something like:

txtbox.Select(txtbox.Text.Length, 0);

Upvotes: 3

Related Questions