ページ内のフォーム オブジェクトを参照する場合は、ドキュメント内のフォーム オブジェクトの配列である「document.forms」オブジェクトを使用できます。次のようなフォームがあるとします。
<form method="post" action="somthing.php" name="myContactForm" id="contact_form">
<input type="text" name="custList" id="custListId" />
</form>
正しい方法で値にアクセスするには、次のいずれかの方法を使用できます。最初にフォームにアクセスし、次に要素にアクセスします。
var form = document.forms['myContactForm']; // use the 'name' attribute as the array key
// or if this is the first form appeared in the page. otherwise increase the index number to match the position of your target form.
var form = document.forms[0];
// or access the form directly
var form = document.getElementById('contact_form');
// now get the element, from the form. you can access form elements, by using their name attribute as the key in the elemetns array property of the form object.
var cust = form.elements['custList'].value();
または、フォームなしでフォーム要素に直接アクセスできます。ドキュメント内の任意の要素をその ID で直接参照できます。ここではフォームは必要ありません。
var cust = document.getElementById('custListId');
これらのステートメントはすべて、IE、firefox、opera、chrome などで実行される有効な JavaScript です。ただし、'name' 属性を呼び出すだけで、IE のフォーム オブジェクトを参照できます。したがって、この行はIEで機能します(そして、あなたが言っているように、クロム。クロムがそれを処理することを知りませんでした):
var cust = myContactForm.custList.value();
IE は、不明なウィンドウ レベルのプロパティ ( myContactForm など) を要素の 'name' 属性に一致させてマップしようとします。