2011-12-14 10 views
0

動的に追加されたフォーム要素を使ってWebフォームを作成しました。その後フォーム要素をナビゲートする方法

document.write('<fieldset name="field__collection__">') ; 
           document.write('<legend align="right" style="color:#FF0066"><code>COLLECTION</code></legend><br />') ; 
           document.write('</fieldset') ; 

: 私は私が興味を持ってフィールドセットでいくつかの選択ボックスを挿入 、いくつかの条件が満たされたときにfieldsetの数を作成し、

例えば、私は次のようにフィールドセットを作成します、フィールドセットにアクセスし、私は選択ボックスを作成するために:

var html = form.elements["field__collection__"].innerHTML ; 
           for(netelement in CUSTOM) 
           { 
             html = html + '<fieldset><legend align="left" style="color:#888888"><code>'+ netelement +'</code></legend>' 
             var x = "__collection__" +'###'+ netelement +'###' ; 
             html = html + '<select name=\"'+ x +'\" multiple="true" size="5" onsubmit="document.getElementById(\'MAIN\').submit()">' ; 
             for(collection in CUSTOM[netelement]) 
               if(collection != "icollection") 
                 html = html + '<option>'+collection+'</option>' ; 
             html = html + '</select>' ; 
             html = html + '</fieldset>' ; 
           } 
           form.elements["field__collection__"].innerHTML = html ; 

の問題は、私のようなフィールドセットにアクセスできることです。form.elements["field__collection__"] をし、これは、Firefox、サ上で動作しますfari、Opera、Chrome、IE8では動作しません(問題はinnerHTMLではありません)。 具体的には、はIE8では未定義です。

答えて

0

この

var fieldSet = document.getElementsByName('field__collection__')[0]; 

のようなあなたのフィールドセットを取得し、その後、「X」の名前を持つフィールドセット内の要素は以下のようになり試してみてください。

var nameOfxInFieldSet = fieldSet.getElemenetsByName('X') 
+0

は、あなたの興味のためにアダムありがとうございました。あなたが書いたのはFirefox上で動作しますが、IEの場合はそうではありません。このようなことが起こる理由は何ですか? – user690182

関連する問題