Harpo
Harpo

Reputation: 187

How make certain field (search box) active when page loads

When a user loads my page, the first element to become active in the browser is one of my menu buttons.

I have a search box (form field) on my page that I want to be the first thing active.

What I mean by "active" is that when the user pushes the tab button, it cycles through all the elements on the site, right. And if users use tab on my site they have to cycle through all the menu buttons before coming to the search field.

Is there a way to say to the browser, "make this field the first active one on page load"? So that when the page has loaded, the user can start typing in the search field right away.

Thank you.

Upvotes: 2

Views: 2079

Answers (2)

Satish Shinde
Satish Shinde

Reputation: 2996

It will be best option for case

   <input type="text" name="YourSearch" id="YourSearch" autofocus>

Upvotes: 0

Aniket Thakur
Aniket Thakur

Reputation: 68975

You can use autofocus for that. Using javascript you can do

document.onload = function() {  
  document.getElementById("textField").focus();
}

OR

you can directly use it as follows

Search : <input type="text" name="search" autofocus><br>

You can read more about it here and can try it out here.

Upvotes: 2

Related Questions