Form API focus on first input When my form load I would like to set the focus on the first field in the form. I know I can use jquery to do this by doing $('inout id').focus();. Where would I put this code so that it only runs on a certain form?

Is there a simpler way?

Updated

Using a mixture of smile's answer and clive's comment the code that got it working in the end was:

$form['#attached']['js'] = array('(function ($){$(document).ready(function() { $(".form-item-field-name input").focus()});})(jQuery);' =&gt; array( 'type' =&gt; 'inline'));
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'));
  }
}