I would like the cursor to be focused on the username field on the login page. So as soon as the page loads the textfield has focus and a user can start typing in their username without first having to click on the field.

Adam

Comments

Oblivious-1’s picture

This is the gist of it (making use of jQuery) to get you started:

$(function(){
    $('#edit-name').focus();
});

--
Erik

waynemwyatt’s picture

If you want the page, every time it's loaded, to look for the field and focus in it, this should work fine. You might need to add a class name to your username input field (in the example below I used 'userfield'). I am not that good with javascript, and I am just learning jQuery, so this may not work, but it should ;)

function onFormLoad(){
      var e;
      if((e = $('input:visible.userfield').get(0))){
            e.focus();
      }
}
 
$(window).load(function(){
      onFormLoad();
})

If you have any questions just reply here...

agerson’s picture

Where do I put this code?

agerson’s picture

Create a scripts.js file in your theme folder and put the following code:

Drupal.behaviors.userNameFocus = function () {
$('#edit-name').focus();
};

Then, in your theme's .info file, put the following line of code:

scripts[] = scripts.js

ceege111’s picture

thanks for the snippet