気が早いのはだめだぞ
<html> <head> <script type="text/javascript"> document.supercalifragilistics.supercalifragilisticexpialidocious.value = "gibberish"; </head> <body> <form name="supercalifragilistics"> <input type="text" name="supercalifragilisticexpialidocious"> </form> </body> </html>
テキストボックスの値を書き換えるだけのhtml。これだとdocument.supercalifragilisticsなんてないよってエラーがでた。そこで、
<html> <head> <script type="text/javascript"> init(){ document.supercalifragilistics.supercalifragilisticexpialidocious.value = "gibberish"; } </head> <body onload="init()"> <form name="supercalifragilistics"> <input type="text" name="supercalifragilisticexpialidocious"> </form> </body> </html>
こんな感じにするとうまくいった。onloadは要素が全て読み込まれてから実行されるから。
htmlファイルは上から順に評価されていくから値を書き換えようとしたときにはまだフォームが作られてないんだってさ。