douyao6842 2015-04-22 05:25
浏览 351

在javascript中动态添加文本框

I dynamically add a text box whenever a user clicks a button to add more, which works fine. However, in PHP when I get the submitted field values by $_POST['skills'] , I only receive the first text box value, not the dynamically added ones. I'm almost positive there is something wrong with the way I am adding the text boxes in javascript. I use the following method to add a text box field:

function addTextBoxField()
{
            var input = document.createElement('input'); 
            input.type = "text";
            input.name = "skills[]";
            input.size = "30";

            var container = document.getElementById("skillfield");
            container.appendChild(input);
}

The HTML code I have for the text box is :

...
<td>
<div id="skillfield">
    <input type="text" size="30" name="skills[]" />
</div>
</td>
<td><a href="javascript:void(0);" class="addLink hidden" onclick="addTextBoxField();"><div class="button">+ Add</div></a></td>

Here is the php code as well:

if ($_SERVER["REQUEST_METHOD"] == "POST")
{ 
     $allskills = $_POST['skills']; 
     $size = count($_POST['skills']);
     print_r($allskills);
}

The output is the following, even though I inputted three values

Array ( [0] => java )

  • 写回答

5条回答 默认 最新

  • dongzhang6544 2015-04-22 05:32
    关注

    Your field name is skills not skill .So it should be $_POST['skills'].$_POST['skills'] is an array in this case. So access try with var_dump($_POST['skills']); and you will see all the values.

    评论

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧