DelphiFAQ Home Search:

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

 

comments8 comments. Current rating: 5 stars (4 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  
rating
2009-01-20, 11:28:07
anonymous  
Thanks :)
2009-05-20, 03:55:47
anonymous from India  
rating
fff
2012-10-23, 03:14:29
anonymous  
rating
I certainly enjoyed the way you explore your experience and knowledge of the subject! Keep up on it. Thanks for sharing the info. http://www.megaabst..berseo.com
2012-11-12, 05:06:18
anonymous from United States  
2017-11-27, 20:11:38
anonymous from Indonesia  

 

 

NEW: Optional: Register   Login
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, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

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.

photo Add a picture: