By solar3000 on
In www.yoursite.com/yourDrupalInstall/user there is a form with a "login" and "password".
How do you set focus to it?
As you probably know, drupal generates this form tag:
<form action="/yourfolder/node/12345" accept-charset="UTF-8" method="post" id="user-login">
...
<input name="name" ....>
There's no "name=..." parameter for the form. How do I get to the text box?
I've tried document.<form>.name.focus().
The form has no name.
Comments
You can
You can use
You can add it to the page with
For a more general solution that puts the focus on the first input for the first form in the main content area you can try something like
You would need to replace #main-group with the id (or class) your theme uses for the main content area.
What is this called? What
What is this called? What keywords so I can research further.
Thanks.
If you mean, "what is the
If you mean, "what is the code", that is jQuery.
Updated answer
Here is what worked for me (six years after nevets' answer) :
Based on https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_...
What's your take on
What's your take on getElementById:
1) The recommendation is not
1) The recommendation is not to use window.onload when using jQuery (which Drupal does)
2) The jQuery code "works" even if the element is not present, in this case, "works" means without error, yours will show an error.
3) Lets see you do the general solution with getElementById :)
I know this is an old thread, but...
I am struggling with this very issue. I have an exposed filter in a views content pane that is displayed in a panel pane. The target input is this:
I have tried several variations of the suggested drupal_add_js code and placed it in several locations (various .tpl files, hook_form_alter functions, etc), all to not avail.
Any assistance greatly appreciated!
Also, "there's a module for that..."
https://www.drupal.org/project/focus
But there are accessability-issues with setting focus, discussed here:
http://drupal.org/node/90324