How can one add inline JavaScript in the validation function for the Form API?
See the docs @https://www.drupal.org/docs/7/api/javascript-api/managing-javascript-in-drupal-7


  drupal_add_js() example:

drupal_add_js(
  'jQuery(document).ready(function () { alert("Hello!"); });',
  array(
    'type' =&gt; 'inline',
    'scope' =&gt; 'footer',
    'group' =&gt; JS_THEME,
    'weight' =&gt; 5,
  )
);

  
  #attached example:

$element['#attached']['js'][] = array(
  'type' =&gt; 'inline',
  'data' =&gt; 'jQuery(document).ready(function () { alert("Hello!"); });',
  'scope' =&gt; 'footer',
  'group' =&gt; JS_THEME,
  'weight' =&gt; 5,
);



Just replace $element by $form.



Original source: https://web.archive.org/web/20160502205421/http://www.failover.co/snippets/drupal-7-attaching-css-and-javascript-forms-or-form-elements