Community Documentation

Focus caret automatically at www.example.com/?q=user

Last updated October 18, 2011. Created by ugerhard on February 7, 2006.
Edited by MGParisi, bekasu, bjornarneson. Log in to edit this page.

This php snippet will automatically give focus to the username field when anonymous users visit www.example.com/?q=user.

The snippet should be inserted immediately before the <?php print $closure;?> tag in your page.tpl.php.

<?php

// If user is not logged in and visits user page,
// focus caret on username text input.
if ((arg(0) == "user") && (!$user->uid)) {
print
"[script type=\"text/javascript\"]\n";
print
"document.getElementById('edit-name').focus()\n";
print
"[/script]\n";
}
?>

About this page

Drupal version
Drupal 4.6.x
Audience
Themers

Archive

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.