Executing JS calls during user login validation (Drupal 7) I need to execute three different JS calls during the login process (for tracking reasons) depending on how the validation goes. I have no idea where to include them:

1. Event: Login failed (wrong password and/or user name)
-&gt; wrong_pass();

2. Event: Incorrect E-Mail format (I am using E-Mail addresses as user names)
-&gt; wrong_email();

3. Event: Login successful
-&gt; login_ok();


How can I catch these events and react to them by executing the respective JS calls?

Thanks in advance!
You could add a validation hook to the user login form &amp; block to add the javascript if the fields fail to validate. 

So to alter the form:

function MODULE_NAME_form_alter(&amp;$form, $form_state, $form_id) {
  // Add the validate function
  if ($form_id == 'user_login_block' || $form_id == 'user_login') {
    // Add your javascript that contains Drupal.behaviors
    drupal_add_js(drupal_get_path('module', 'MODULE_NAME') . '/MODULE_NAME.js');
    $form['#validate'][] = '_MODULE_NAME_user_login_validate'; // this is the function name
  }
}


Then in your validation function:

function _MODULE_NAME_user_login_validate($form, $form_state) {
  // Do your field validation here, I'll only showcase one of them (username)
  if(!valid_email_address($form_state['values']['name'])) {
    // Add a setting to the Drupal.settings variable available in javascript
    drupal_add_js(array('MODULE_NAME' =&gt; array('name' =&gt; FALSE)), 'setting');
  }
}


Finally in your MODULE_NAME.js file you can check to see if the setting was set:

if(Drupal.settings.MODULE_NAME.name == FALSE) {
  wrong_email();
}