Last updated 26 October 2010. Created on 22 June 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: £'.number_format($price,2);
    $code = '
      if ($("#price").size() == 1) {
        $("#price").html(\''.$div.'\');
      } else {
        $("#edit-submit").before(\'
' . $div . '
\'); } '; return $code; } }

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

Comments

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.

Sateesh Nutulapati
Devops Solutions Architect 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 http://drupal.org/project/uc_auction so that I can have live auctions?
if yes please tell me where i can put the code

thanks