IE.document.formsからフォームの情報取得が行えます。
フォームと聞くと入力項目フォームが浮かびますが、
それらはformsオブジェクトの中にあるelementsオブジェクトの操作により触れるので、
次以降の記事で言及します。
テキストボックスやセレクトボックスなどのelementsの一つ上のformsオブジェクトから、
フォームの送信先やエンコード方式などの全般的な情報を取得できます。
■フォーム
- フォームの総数
- IE.document.forms.length
■フォームのオブジェクト(0からの数値を指定)
- 送信先
- IE.document.forms[0].action
- エンコード方式(1)
- IE.document.forms[0].encoding
- エンコード方式(2)
- IE.document.forms[0].enctype
- 送信形式
- IE.document.forms[0].method
- ターゲット
- IE.document.forms[0].target
というわけで、
具体的にスクリプトを実行させて、結果を見てみましょう。
IE = CREATEOLEOBJ( "InternetExplorer.Application" ) |
IE.navigate( "http://canal22.org/sample0004/" ) |
UNTIL !IE.busy AND IE.readyState = 4 |
PRINT " IE.document.forms.length=" + IE.document.forms.length |
FOR A = 0 TO (IE.document.forms.length - 1) |
PRINT " " + (A+1) + "番目のフォーム" |
PRINT " IE.document.forms.action=" + IE.document.forms[A].action |
PRINT " IE.document.forms.encoding=" + IE.document.forms[A].encoding |
PRINT " IE.document.forms.enctype=" + IE.document.forms[A].enctype |
PRINT " IE.document.forms.method=" + IE.document.forms[A].method |
PRINT " IE.document.forms.target=" + IE.document.forms[A].target |
resetとsubmitもして見ましょう
IE.document.forms[0].resetでフォームの各項目の入力値がリセット、
IE.document.forms[0].submitでサブミット、送信ができます。
IE = CREATEOLEOBJ( "InternetExplorer.Application" ) |
IE.navigate( "http://canal22.org/sample0004/" ) |
UNTIL !IE.busy AND IE.readyState = 4 |
FOR A = 0 TO (IE.document.forms.length - 1) |
IE.document.forms[A].elements[0].value = "仮入力" |
MSGBOX( "リセットします。入力値をチェック" ) |
FOR A = 0 TO (IE.document.forms.length - 1) |
IE.document.forms[A].reset() |
FOR A = 0 TO (IE.document.forms.length - 1) |
IE.document.forms[A].elements[0].value = "仮入力" |
MSGBOX( "再度、入力。次は送信 ※受信用のプログラムは無いため遷移先のエラーにはなります。" ) |
num = IE.document.forms.length - 1 |
IE.document.forms[num].submit() |