Need help setting Views exposed filter input focus

JSCSJSCS's picture

As the subject implies, I desire for usability purposes to set the focus to the first input of an exposed input field. I've searched and can only find mention of something like this:

<?php
drupal_add_js
("$('#edit-name').focus();", 'inline');
?>

But there no mention of where to put it or how to use it, or if '#edit-name' is the ID of the input text box or the name of it.

I've tried putting the above in a custom module, in the page.tpl and others.

Obviously, I have tried several iterations and locations, but cannot find the key to open this lock.

Any help appreciated!

Comments

It look like you may have to

el_reverend's picture

It look like you may have to wrap your code in (function ($) {... })(jQuery); or jQuery() since you cannot rely on $().

Maybe something along the lines of:

<?php
  drupal_add_js
('jQuery(document).ready(function () {
   jQuery('
input#edit-name').focus();
 
});', 'inline');
?>

LA Drupal (Los Angeles Drupal)

Group events

Add to calendar

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week