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 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应