Selecting all text in HTML text input when clicked

You can use this javascript snippet:

<input onClick="this.select();" value="Sample Text" />

But apparently it doesn’t work on mobile Safari. In those cases you can use:

<input onClick="this.setSelectionRange(0, this.value.length)" value="Sample Text" />

Leave a Comment