I've found a nice plugin to bind hotkey combinations like Ctrl+A for submit buttons, but I don't understand how I can apply this to my form submit button.

Can anyone put me on the right direction?

1 Answer 1


It looks like what you'll want to do is add it in a separate js file in a module. Use hook_form_alter() or hook_form_FORM_ID_alter()and identify the form that you want the script run on. Then In hook_form_alter() use drupal_add_js(drupal_get_path('module', 'mymodule') . '/mymodule.js'); to add the JavaScript file to that page.

Also in hook_form_alter(), you'll want to identify the button you want to add this to and add a prefix and suffix markup to it.

$form['button']['#prefix'] = array('<div class="my-button-class">');
$form['button']['#suffix'] = array('</div>');

In the JavaScript file, where you see div.foo you'll want to enter the name of that div that you created on the button.

$('div.my-button-class').unbind('keydown', 'Ctrl+a', fn);

Also in hook_form_alter() you need to add a class to an input or button or whatever you are using.

$form['field']['#attributes'] = array('class' => array('my-other-class'));

For this, in the js file you need to replace:

$('input.my-other-class').bind('keyup', '$', function(){

EDIT: Note the input.class. If you're targeting a different type of element this will need to be changed accordingly. Same with div. class. I think you can also do IDs like input#my-input-id.

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.