フォーカスを移動する

フォームの入力エリアに入力ポインタを合わせます。

書式

document.FormName.ElementName.focus()
document.forms[n].elements[N].focus()

FormNameはフォーム名、ElementNameはエレメント名。
forms[n]は n番目のフォーム(番号は 0から)。elements[N] は n番目のエレメント(番号は 0から)。

サンプル

<body onload="document.f.q.focus()" topmargin=3 marginheight=3>
  <form action="/search" name=f>
    <input name=hl type=hidden value=en>
    <input maxlength=2048 name=q size=55 title="Search" value="">

「document.f.q.focus()」は「document.forms[0].elements[1].focus()」と書いてもよい。