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条)

报告相同问题?

悬赏问题

  • ¥20 simulink中怎么使用solve函数?
  • ¥30 dspbuilder中使用signalcompiler时报错Error during compilation: Fitter failed,求解决办法
  • ¥15 gwas 分析-数据质控之过滤稀有突变中出现的问题
  • ¥15 没有注册类 (异常来自 HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
  • ¥15 知识蒸馏实战博客问题
  • ¥15 用PLC设计纸袋糊底机送料系统
  • ¥15 simulink仿真中dtc控制永磁同步电机如何控制开关频率
  • ¥15 用C语言输入方程怎么
  • ¥15 网站显示不安全连接问题
  • ¥15 51单片机显示器问题