Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically selecting text in an input field on iOS devices (mobile Safari)

How do you programmatically select the text of an input field on iOS devices, e.g. iPhone, iPad running mobile Safari?

Normally it is sufficient to call the .select() function on the <input ... /> element, but this does not work on those devices. The cursor is simply left at the end of the existing entry with no selection made.

like image 942
sroebuck Avatar asked Jul 17 '10 15:07

sroebuck


2 Answers

input.setSelectionRange(0, 9999); 

https://developer.mozilla.org/en/DOM/Input.select

like image 86
jobwat Avatar answered Oct 13 '22 05:10

jobwat


Nothing in this thread worked for me, here's what works on my iPad:

// t is the input field setTimeout(function() {     t.setSelectionRange(0, 9999); }, 1); 
like image 41
nkrop Avatar answered Oct 13 '22 05:10

nkrop