Last updated October 26, 2010. Created on June 22, 2009.
Edited by gapa, LeeHunter, JohnNoc, kenorb. Log in to edit this page.

Ajax Trigger module allows you to do specified actions on the server on JavaScript events on specified fields.

Example #1 - Calculating price in real-time using hook_ajax_trigger

1. Active Javascript Events for specified Field on Field Settings Page (admin/content/node-type/party/fields/field_name)
2. Example code:

 * Implementation of hook_ajax_trigger().
function foo_ajax_trigger($form, $field, $op) {
  $form_id = $form['form_id'];
  if ($form_id == 'my_form_name') {
    // Load required values from form
    $price = (int)$form['field_foo'][0]['value'];
    $div = 'Calculated price: &pound;'.number_format($price,2);
    $code = '
      if ($("#price").size() == 1) {
      } else {
        $("#edit-submit").before(\'<br><div id="price">' . $div . '</div>\');
    return $code;

Looking for support? Visit the forums, or join #drupal-support in IRC.


Marujah’s picture

Hey, can you tell me where to save this Code! in a new Module? HELP PLEASE

nvl.sateesh’s picture

You need to add this code as a hook implementation in your module. The 'foo' in the function name refers to your module name.

NVL Sateesh
Drupal Geek at New Target, Inc.

joelbox-Mondial-IT’s picture

How would the jquery code look in this example?

niharjyoti’s picture

where i will have to put this code..& how it will be bind with cck-field..can you tell me step by step process

wallbay1’s picture

hi do you think I can use this on the uc auction module so that I can have live auctions?
if yes please tell me where i can put the code