[development] Drupal 7 - Input Field and Javascript Events

Michael Favia michael.favia at gmail.com
Thu Oct 27 16:18:39 UTC 2011

On 10/27/2011 10:45 AM, Carl Wiedemann wrote:
> A better method of doing this is to specify JS event handlers via a 
> separate file in drupal_add_js() using Drupal.behaviors. I don't know 
> of go-to documentation for this off of the top of my head, but do some 
> searching and look at examples in other core modules.
Perhaps something like:

// Using the closure to map jQuery to $.

(function ($) {

   // Store our function as a property of Drupal.behaviors.

   Drupal.behaviors.myModuleSecureLink = {

     attach: function (context, settings) {

       $('#formid #input-name').bind('focus', function() {
         alert('User clicked on "foo."');






Michael Favia                   michael at favish.com
tel. 512.669.5650            http://www.favish.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20111027/d18f4503/attachment.html 

More information about the development mailing list