dpl74687 2014-10-23 20:09
浏览 40

php在复选框上添加一个文本框不会发布

I have code that adds input text when the box is checked and it shows up but getting the value from the code does not work. Here is my code:

<input name=ship[] type=checkbox value=example id=Ex>Application Model Example
<span id='Location'>& nbsp;</span>

var checkbox = document.getElementById('Ex');
checkbox.addEventListener('change', function () {
if (document.getElementById('modelType')) {
    document.getElementById('modelType').remove();
} else {
      var input = document.createElement("input");
      input.name = 'modelType';
      input.id = 'modelType';
      input.type = 'text';
      input.placeholder = 'Model Type';
      input.required;
      document.body.appendChild(input);
      var foo = document.getElementById('Location');
      foo.appendChild(input);
}
});

<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
echo "Model Type is $modelType";
}

The text input only appears after I click the checkbox which is exactly what I want, but when I go to get the value in the text input in POST is never appears? Also it would be nice if the text input was required, but input.required; does not work (that was just a guess)

  • 写回答

1条回答 默认 最新

  • dqpfkzu360216 2014-10-23 20:14
    关注

    You are not using PHP properly. It has not for a LONG time now auto-created variables for you based on form-inputs. This is a GOOD thing. register_globals is dead, gone, and gloriously so.

    Your code should be

    echo "Model Type is {$_POST['modelType']}";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据