How can I create custom jquery event to use in event:

$form['submitted']['subject']['#ajax'] = array(
  'callback' => 'suggest_ajax_callback',
  'effect' => 'fade',
  'event' => 'change',

for example I want execute suggest_ajax_callback each time user enter Space while filling text-field. so "How Can I Pay?" will cause 3 time execution...

1 Answer 1


The solution for your question is not handled compelety by back-end of drupal.

By default drupal ajax not support customized event
You can acheive your means by jquery and ajax(non-drupal ajax)
Something like this

For using get data by jquery ajax you need first seta menu link for listen to your ajax requst, and in callback of your menu you passed back a block or any data you want.

function yourmodule_menu () {
   $items['youruniqepath'] =array(
        'title' => 'my menu',
        'description' => 'A menu link to handle ajax request',
        'page callback' => 'yourhandlerfunction',
        'acess callback' => TURE, //you can set it with your permission
  return $items;

and in yourhalderjust need pass a block

function yourhandlerfunction () {
  //with any method you want get your block,
  // I suggest something like this
    $block = module_invoke('module_name', 'block_view', 'block_delta');
    print render($block);


and in your clientside get it with something like this

  $('#yourelement').change(function() {
    if( checkfor your means) {
                       type: "POST",
                       url: 'youruniqepath',
                       //data: {}, you can also pass block name and act more dynamicly
                      success: function (data){


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.