使用 php 变量中的值在网站上创建下拉列表?
我正在创建一个表单,用户可以在需要数据时向其表单添加更多字段。
我正在使用一个 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');
I am creating a form that the user can add more fields to their form if they need them for data.
I am using a javascript function which is triggered by a action button that creates a row of textboxes and one pull down field.
However in that row I need a pull down with the options "Yes and No", I already have them in a php array variable called $success
This is what I have to try and create a pull down but its not working.
ta[n]=document.createElement('option');
ta[n].value = <?php echo $success; ?>;
ta[n].name='success'+n;
Could someone help me out thanks for your time :)
This is the bulk of the current code
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');
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
给你(我认为这就是你想做的):
http://jsfiddle.net/maniator/4brz2 /
Here you go (i think this is what you wanted to do):
http://jsfiddle.net/maniator/4brz2/