Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I have a custom form that is displayed in a custom block. That block is a popup div. When a user fills the form successfully it's displaying success message.

I want to attach a jQuery that will hide that div after 4 seconds. I know about jQuery function .delay(4000), but how can I add it into the AJAX callback?

This is a part of my custom module:

<?php
    function custom_alter_form($form, &$form_state) {
        $form['submit'] = array(
            '#type' => 'submit',
            '#value' => t('Submit'),
            '#ajax' => array(
                'callback' => 'custom_alter_ajax_submit',
                'effect' => 'fade',
                'wrapper' => 'custom-alter-form',
                'method' => 'replace',  
                'event' => 'click',
                ),      
            );
        return $form;

    }
    /**
     * Ajax callback function.
     */
    function custom_alter_ajax_submit($form, &$form_state) {    
        $form_state['rebuild'] = TRUE;
        if (form_get_errors()) {
            return $form;
        } else {
            return '<h2>' . t('Your request has been successfully') . '</h2>';//This message is displaying properly.

       drupal_add_js('jQuery(document).ready(function () { alert("Hello!"); });', 'inline'); //I've tried with this inline jQuery but it didn't work.

        } 
    }
?>

I've also read about drupal_add_js(drupal_get_path('module', 'mymodule') .'/mymodule.js'); but how can I attach this into the AJAX handler?

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.