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.

    评论

报告相同问题?

悬赏问题

  • ¥20 蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏