How can one add inline JavaScript in the validation function for the Form API? I found that there is a way to add javascript files in the form validation function as stated in "drupal_add_js not work in form validation failed". 

However, I would like to know how to add javascript using the drupal_add_js function with the inline option. I would just like to execute some javascript code while I am in the validation function of the Drupal 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