Drupal 7 - Input Field and Javascript Events
Hi, I wrote a module and this I call this hook: agenda0_form_id_form_alter(&$form, &$form_state, $form_id) I need to set onClick event in an input field, but Drupal 7 add no events in my input texfield. $form['field_album_title'][$form['field_album_title']['#language']][0]['#attributes']['onchange']="Javascript: ag_change_txt(this.value,'agenda_title');"; Where is my fault? Thanks for reply! ADM
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. Carl Wiedemann Website design and development consulting carl.wiedemann@gmail.com | skype: c4rlww
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."'); }); } } }(jQuery)); || | | -- Michael Favia michael@favish.com tel. 512.669.5650 http://www.favish.com
participants (3)
-
Carl Wiedemann -
linuxlover -
Michael Favia