Sometimes you may want to automatically select all the text in a text box when it receives focus. This saves your user from having to hit delete or backspace to empty the previous contents. This happens frequently when form validation code detects an error and automatically sets the focus using code such as:
document.forms[0].txtName.focus();
To enable automatic selection, you need to call the select method with the onfocus event. Your HTML should look like this: