javascipt 变量赋给php,如何将JavaScript变量传递给PHP

这篇博客讨论了如何在JavaScript中动态创建带有'添加更多行'功能的表单,并在用户提交表单时,将创建的行数传递到PHP页面。作者遇到的问题是如何在PHP中获取并显示JavaScript中创建的文本框数量。解决方案是通过在表单中添加隐藏字段来存储行数,并在提交时更新其值。
摘要由CSDN通过智能技术生成

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

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

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

有任何想法吗?

谢谢

这是我的js功能

window.οnlοad=function()

{

inp=document.getElementsByTagName('input');

for(c=0;c

{

if(inp[c].value=='add')

{

inp[c].οnclick=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 += '
';

n++;

}

}

}

//-->

}

解决方法:

您应该添加到您的表单,并在提交表单时将其值更新为行数.

标签:post,javascript,php

来源: https://codeday.me/bug/20191102/1991553.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值