I am currently developing a module in Drupal. I made a button that show a dialog box whenever it’s clicked.
function myid_init() { drupal_add_js(drupal_get_path("module", "myid") . "/js/jquery-1.11.2.min.js"); drupal_add_js(drupal_get_path("module", "myid") . "/js/myid.js"); } function myid_menu() { $items = array(); $items['admin/settings/myid'] = array( 'title' => 'myid Settings', 'description' => 'Configuration options for the myid module', 'page callback' => 'myid_admin_settings', 'access callback ' => 'user_access', 'access arguments' => array('administer site configuration'), ); return $items; } function myid_admin_settings() { return drupal_get_form('myid_settings_form'); } function myid_settings_form() { $form = array(); $form['myid_registrar_button'] = array( '#type' => 'button', '#value' => '...', '#attributes' => array( 'id' => 'myid_registrar_button', ), ); return $form; }
The JavaScript code is the following
$(function(){ $('#myid_registrar_button').on('click', function(e) { e.preventDefault(); alert("Eww"); }); });
Whenever I click a button, it refreshes and it doesn’t show anything.
It seems the event is not captured. The console doesn’t show errors.
What am I missing?
Sponsored by SupremePR