Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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(\'<h1>'.$div.'</h1>\');
} else {
$("#edit-submit").before(\'<br><div id="price">' . $div . '</div>\');
}
';
return $code;
}
}
Comments
Hey, can you tell me where to
Hey, can you tell me where to save this Code! in a new Module? HELP PLEASE
You need to add this code as
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.
How would the jquery code
How would the jquery code look in this example?
where i will have to put this
where i will have to put this code..& how it will be bind with cck-field..can you tell me step by step process
hi do you think I can use
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