dongtu0088 2012-01-18 05:13
浏览 47
已采纳

用jquery,php和mysql动态添加一个选择框?

Ok I have looked at a few questions on here concerning this topic. But I can not seem to find exactly what I am looking for. I need some help!! I need to dynamically create a select box in a form using jquery, php and mysql. Here is how I have the original select box now without the need to add a new one:

<select name="material" id="selectList">
  <?php
  $get_material = mysql_query("SELECT DISTINCT Familia, anchocm FROM MYS")
     or die(mysql_error());

  while ($info = mysql_fetch_array($get_material)) {
     echo "<option value=\"".$info['anchocm']."\">".$info['Familia']."</option>
  "; 
  }

   ?>
  </select>

It gets the information from a mysql database and populates the fields. Now I need to add a button next to this select box adding another select box identical to this one. So that they may choose one option in each select box. I have no idea how to go about doing this. If anyone has a better suggestion to use I am open. I just need to get this done before tomorrow morning. Thank you so much in advance!

  • 写回答

2条回答 默认 最新

  • douzhanlie9209 2012-01-18 05:38
    关注

    Say you have a button next to your select box:

    <input type="submit" value="Copy" id="copy" />
    

    In jQuery:

    $("#copy").click(function(e) {
       $("#foon").clone().removeAttr('id').insertAfter(this);
       e.preventDefault();
    });
    

    You should also change the name of the select to "material[]" so you can post an arbitrary number as an array.

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

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 虚心请教几个问题,小生先有礼了
  • ¥30 截图中的mathematics程序转换成matlab