Skip to content
Advertisement

How do you automatically set the focus to a textbox when a web page loads?

How do you automatically set the focus to a textbox when a web page loads?

Is there an HTML tag to do it or does it have to be done via Javascript?

Advertisement

Answer

If you’re using jquery:

JavaScript

or prototype:

JavaScript

or plain javascript:

JavaScript

though keep in mind that this will replace other on load handlers, so look up addLoadEvent() in google for a safe way to append onload handlers rather than replacing.

Advertisement