我点击一个带有“添加更多行”按钮的动态表单时,JavaScript函数会使用适当的ID创建一行新的文本框。

问题是,如何将计数器变量从JavaScript函数传递到我的下一个php页面,以便它现在可以接收多少行文本框来接收$_POST

香港专业教育学院有我的JavaScript函数,但是我缺少它创建自己的行中的数据。

有任何想法吗?

谢谢

这是我的js功能

window.onload=function()
{

inp=document.getElementsByTagName('input');
for(c=0;c<inp.length;c++)
    {
        if(inp[c].value=='add')
        {
           inp[c].onclick=function()
            {
                n=15;

               x=document.createElement('input');
               x.setAttribute('rows',1);
               x.setAttribute('cols',20);
               x.name='time'+n;
               document.getElementById('txtara').appendChild(x)
               x=document.createElement('input');
               x.setAttribute('rows',1);
               x.setAttribute('cols',20);
               x.name='event'+n;
               document.getElementById('txtara').appendChild(x)
               x=document.createElement('input');
               x.setAttribute('rows',1);
               x.setAttribute('cols',20);
               x.name='supplies'+n;
               document.getElementById('txtara').appendChild(x)

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



        y = document.createElement('option');
        y.value = 'Yes';
        y.name = 'success' + n;
        y.innerHTML = y.value;

        x = document.createElement('option');
        x.value = 'No';
        x.name = 'success' + n;
        x.innerHTML = x.value;


        sel.appendChild(y);
        sel.appendChild(x);


        document.getElementById('txtara').appendChild(sel);
        document.getElementById('txtara').appendChild(sel);
        document.getElementById('txtara').appendChild(sel);


               x=document.createElement('input');
               x.setAttribute('rows',1);
               x.setAttribute('cols',20);
               x.name='comment'+n;
               document.getElementById('txtara').appendChild(x)

               document.getElementById ('txtara').innerHTML += '<br>';


        n++;

           }
         }

    }
    //-->
}

最佳答案

您应该在表单中添加<input type="hidden" name="num_rows" value="0">并将其值更新为提交表单时的行数。

10-05 20:30
查看更多