IEのFormのデータを保存、復元する方法

JavaScriptでFormの値をJavaScriptとして保存し、
再度実行すれば、Formの値を復元するスクリプトです。
(Web Development Helperのスクリプトコンソールを利用します)

長大なFormのテストデータ入力時に役立つかもしれません。

 // 準備
 //     ・以下のページから「Web Development Helper」をダウンロードしてください。
 //       http://projects.nikhilk.net/Projects/WebDevHelper.aspx 
 //     ・ダウンロードしたファイルをインストールしてください。
 //     ・IEを起動し、「ファイル」メニューの「エクスプローラーバー」から「Web Development Helper」を
 //       選択してください。
 //     ・表示されたメニューの「HTTP Logging▼」を選択し、「Script Console」を選択してください。
 //     ・「Script Console」の右の「Enable Debugging」にチェックを付けてください。
 //        (「インターネットオプション」の「詳細」タブでスクリプトのデバッグを許可している必要があります。)
 //    
 // 使い方
 //     1:右ペインの「LoadScript」からこのスクリプトファイルを開き、「Execute」をクリックする。
 //     2:左ペインに表示された実行結果を全選択し、「Copy」をクリックする。
 //        (フォームのデータを復元するためのJavaScriptがコピーされます)
 //     3:再度同じ画面を開き、2でコピーしたスクリプトを実行すればフォームの値が復元されます。
 //        (select,checkbox,radio,hiddenの項目も復元されます)
 var scr = "";
 
 var selNm = "";
 var selType = "";
 var selIdx = 0;
 var aryIdx = "";
 
 var nameHash = new Array();
 
 dall = "window.document.all['";
 var end = ";\r\n";
 
 var forms;
 if( window.frames.length > 0 )
 {
     // フレームがある場合は最初のフレームからデータを取得する
     forms = window.frames[0].document.forms;
     dall = "window.frames[0].document.all['"
 }
 else
 {
     // フレームがない場合
     forms = window.document.forms;
 }
 
 for( i = 0; i < forms.length; i++ )
 {
     frm = forms[i];
     for( j = 0; j < frm.all.length; j++ )
     {
         tag = frm.all[j];
         if( tag.type != undefined )
         {
             // viewstateは保存しない
             if( tag.name == "__VIEWSTATE" )
             {
                 continue;
             }
             
             if( frm.all[tag.name] != undefined && 
                 frm.all[tag.name].length >= 2 && 
                 frm.all[tag.name][0].type == tag.type )    // selectのname属性が1つの場合と2つの場合で動作が異なるので回避
             {
                 if( nameHash[tag.name] == undefined )
                 {
                     nameHash[tag.name] = 0;
                 }
                 aryIdx = "[" + nameHash[tag.name] + "]";
                 nameHash[tag.name] += 1;
             }
             else
             {
                 aryIdx = "";
             }
             
             // text,textarea,hidden項目を保存
             if( tag.type == "text" ||  tag.type == "textarea" || tag.type == "hidden" )
             {
                 scr +=  dall + tag.name + "']" + aryIdx + ".value = '" + tag.value.replace(/\r\n/g, '\\r\\n') + "'" + end;
             }
             else if( tag.type == "checkbox" ||  tag.type == "radio" )
             {
                 scr +=  dall + tag.name + "']" + aryIdx + ".checked = " + tag.checked + end;
             }
             else if( tag.type == "select-one" || tag.type == "select-multiple" )
             {
                 selIdx = 0;
                 selNm = tag.name;
                 selType = tag.type;
             }
         }
         else
         {
             if( tag.tagName == "OPTION" )
             {
                 if( selType == "select-one" && tag.selected )
                 {
                     scr +=  dall + selNm + "']" + aryIdx + ".options[" + selIdx + "].selected = " + tag.selected + end;
                 }
                 else if( selType == "select-multiple")
                 {
                     scr +=  dall + selNm + "']" + aryIdx + ".options[" + selIdx + "].selected = " + tag.selected + end;
                 }
                 selIdx++;
             }
         }
     }
 }
 
 Debug.writeln(scr);