0

I have one button and onclick i want javascript function to be called which contains alert message...............in drupal

i tried many things like........... 1)i created button using
$form['click'] = array( '#type' => 'button', '#attributes' => array('onclick' =>_____________),//dnt know what to give for onclick '#value' => t('click'), );

2)used drupal_add_js(drupal_get_path('module', 'document').'/eg.js', 'module');in hook_form_alter()

3).js file is as follows function message() { alert("Catch ->This alert box was called"); } -->

want alert message to be displayed on button click. Kindly help................ Thanks in advance

1 Answer 1

1
$form['search_something'] = array(
      '#type' => 'button',
      '#value' => t('Search'),
      '#attributes' => array('onclick' => 'searchsomething()),
  );

this is the piece of code to call javascript on button click.

Javascript function

function searchsomething(){
  alert("hello");
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.