Executing JS calls during user login validation (Drupal 7)
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();
}