dongyou6847 2016-08-13 09:48
浏览 22
已采纳

隐藏可见性的输入字段值未发布

I have a select box with options of numbers in it.Whenever user selects an option i am displaying input box through jquery depending on the number selected.So for this the input box are initially hidden. Now the problem is that when i try to post the value of those input box, they are not getting posted. Here is html code-

<form action="data.php" method="POST">
    Select the number of company:
      <select name="num_of_comp" id="num_of_comp">
        <option value="1">1</option>
        <option value="2">2</option>
      </select>     
<div id="div1" style="visibility:hidden;">
<label for="dbname">database name:</label>
<input type="text" name="db1" id="db1" />
<input type="submit" name="submit" id="submit" />
</div>
<div id="div2"  style="visibility:hidden;">
<label for="dbname">database name:</label>
<input type="text" name="db1" placeholder="db1 name"/>
<input type="text" name="db2" placeholder="db2 name"/>
<input type="submit" name="submit" id="submit" />
</div> 

Here is the script that dynamically displays the input box -

$('#num_of_comp').on('change',function(){
    if( $(this).val()==="1"){
    $("#div1").css("visibility", "visible");
     $("#div2,").css("visibility", "hidden");
    }
    else if( $(this).val()==="2"){
    $("#div2").css("visibility", "visible");
     $("#div1").css("visibility", "hidden");
    }

Here is php code-

$i = $_POST['num_of_comp'];
if($i == '1'){
$db1 = $_POST['db1'];
echo $db1;

Here I am not getting the value of db1. Thanks in advance.

  • 写回答

3条回答 默认 最新

  • duancheng1955 2016-08-13 09:52
    关注

    You can not set same id to multiple fields, id should be unique for all fields.

    so set different ids to all fields in form

    Even the name of the all input fields should be unique here.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据