on click of button i want hi message to be displayed using javascript in drupal.I have made a .js file and know that to incude that i must use drupal_add_js(drupal_get_path('module', 'document') .'/click.js'); but the problem is to create button i used $form['click'] = array( '#type' => 'button', '#attributes' => array('onclick' =>drupal_add_js(drupal_get_path('module', 'document') . '/cancel.js')), '#value' => t('click'), );
I want that hi message which i have included in js file to be shown when button is clicked. Please help
Hi thanx for your concern.......... here is the way i proceeded in .module file
function document_form(&$node) { $form['click'] = array( '#type' => 'button', '#attributes' => array('onclick' =>message()), '#value' => t('click'), ); }
function document_form_alter(&$form, &$form_state, $form_id) { drupal_add_js(drupal_get_path('module', 'document').'/cancel.js', 'module'); $settings['click'] = array( 'nid' => $form['nid']['#value'], 'cid' => $form['cid']['#value'], 'uid' => $form['uid']['#value'], 'pid' => $form['pid']['#value'], ); drupal_add_js($settings, 'setting'); }
and my .js file code is as follows:
function message() { alert("This alert box was called"); }
<body>
</body>
but still onclick of button i m not getting the message "This alert box was called" Kindly help where the problem is coming now....... Thanx in advance.... in wait of your response