Starting on <input> on page load?

Soldato
Joined
15 Jan 2004
Posts
10,206
As on Google, when you load the page up, you can start typing in the input straight away without clicking the box.

I've done this before but cannot remember how, anyone know?
 
In pure JavaScript try the focus() function of an input box:

Code:
<script type="text/javascript">
      document.getElementById('search').focus();
</script>
If you use jQuery then use focus:

Code:
<script type="text/javascript">
      $(document).ready(function(){
        $("#search").focus();
      });
</script>
 
use window.onload() if going pure JS:
Code:
window.onload(function(){ 
  document.getElementById("search").focus();
});
 
Back
Top Bottom