DelphiFAQ Home Search:

How to focus on an input field when the page is loaded

 

comments3 comments. Current rating: 5 stars (2 votes). Leave comments and/ or rate it.

The object model provides a .focus() method.
Simply reference the field and call its focus method in the onload event as shown below:

<body onload="document.getElementById('searchterm').focus();">

// .. here's the FORM. Make sure to define the ID tag,
// not just the name tag.
<textarea id="searchterm">

Comments:

2006-09-18, 21:38:17
anonymous from United States  
rating
2006-09-25, 04:35:03
anonymous from United Kingdom  
IS there a way to do this without Javascript? IE will not allow this in an HTML page run from hard disk...
2007-02-17, 19:52:32
anonymous from  
rating

 

 

Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option.
 
It seems that you are
from Washington, US .

Info/ Feedback on this

Show city and country
Show country only
Hide my location
Leave your comment here:
Please type in the code:
photo Add a picture:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity. The owner of this web site reserves the right to delete such material.