Most of the answers here work well, but I don't see anyone mentioning that you can accomplish this very simply without needing to define extra JS elsewhere.
Essentially, the accepted answer can be condensed into just this:
<input value="Click me to select!" onfocus="this.select()" />