Form API focus on first input
You can attach js only to your form. Use hook_form_alter()

function your_module_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  if($form_id == 'my_form'){
  // Add JavaScript file
  $form['#attached']['js'] = array(drupal_get_path('module', 'your_module') . '/your_file.js');

  // Or for inline JavaScript
  $form['#attached']['js'] = array('/* some javascript here */' =&gt; array( 'type' =&gt; 'inline'));
  }
}