0

ユーザーがデータに必要な場合にフォームにフィールドを追加できるフォームを作成しています。

テキストボックスの行と1つのプルダウンフィールドを作成するアクションボタンによってトリガーされるjavascript関数を使用しています。

ただし、その行では、「はい」と「いいえ」のオプションを使用してプルダウンする必要があります。$success という名前の php 配列変数に既にそれらがあります。

これは私が試してプルダウンを作成しなければならないものですが、うまくいきません。

ta[n]=document.createElement('option');
ta[n].value = <?php echo $success; ?>;
ta[n].name='success'+n;

誰かが私を助けてくれませんか :)

これは現在のコードの大部分です

if(inp[c].value=='add') 
    {
       inp[c].onclick=function() 
        {
           ta[n]=document.createElement('input');
           ta[n].setAttribute('rows',1);
           ta[n].setAttribute('cols',20);
           ta[n].name='time'+n;
           document.getElementById('txtara').appendChild(ta[n])
           ta[n]=document.createElement('input');
           ta[n].setAttribute('rows',1);
           ta[n].setAttribute('cols',20);
           ta[n].name='event'+n;
           document.getElementById('txtara').appendChild(ta[n])
           ta[n]=document.createElement('input');
           ta[n].setAttribute('rows',1);
           ta[n].setAttribute('cols',20);
           ta[n].name='supplies'+n;
           document.getElementById('txtara').appendChild(ta[n])
          var sel = document.createElement('select');
4

1 に答える 1

0

どうぞ(これがあなたがやりたかったことだと思います):

http://jsfiddle.net/maniator/4brz2/

var sel = document.createElement('select');

var ta = [];
var n = 0;

ta[n]=document.createElement('option');
ta[n].value = 'YES';
ta[n].name='success'+n;
ta[n].innerHTML = ta[n].value;
n++;
ta[n]=document.createElement('option');
ta[n].value = 'NO';
ta[n].name='success'+n;
ta[n].innerHTML = ta[n].value;
n++;

sel.appendChild(ta[0]);
sel.appendChild(ta[1]);


document.getElementById('here').appendChild(sel);
于 2011-06-30T16:30:39.563 に答える