I would like the value of the input text box to be highlighted when it gains focus, either by clicking it or tabbing to it.
<html> <body> <script> function focusTest(el) { el.select(); } </script> <input type='text' value='one' OnFocus='focusTest(this); return false;' /> <br/> <input type='text' value='two' OnFocus='focusTest(this); return false;' /> </body> </html>
When either input field is clicked in Firefox or IE, that field is highlighted. However, this doesn’t work in Safari. (NOTE: it works when tabbing between fields.)
I noticed Safari is actually selecting the text then removing the selection quickly.
So I tried this quick workaround that works in all browsers:
Edit :
Upon further testing it turns out the OnMouseUp event is clearing the selection so it is enough to add
to the input element for things to work as they should.