douchendan0040 2012-05-20 04:48
浏览 67
已采纳

如何从PHP中的多个选择/列表框中获取值?

i want to know that how to get multiple selectbox values in php means that i have more than 1 select box on a page and it can be increased when user click on addmeans that a page can contain numerous selectboxes now plz tell me how to get the values from that boxes and also how do i get know that how many select boxes were used by user

i think an array should be used but i dont know how??

    <select name="select" id="select">

<option value="1">value1</option>

<option value="2">value2</option>

<option value="3">value2</option>

</select>

    <select name="select" id="select">

<option value="1">value1</option>

<option value="2">value2</option>

<option value="3">value2</option>

</select>



    <select name="select" id="select">

<option value="1">value1</option>

<option value="2">value2</option>

<option value="3">value3</option>

</select>

like in above example how do i get know that how many selectboxes were used and how to get value of each box

code for adding the new dropdown

function addRow()
            {
                var newRow = document.all("tblGrid").insertRow();


                var oCell = newRow.insertCell();
                oCell.innerHTML = "<select name='select' id='select'><option value='1'>1</option><option value='2'>2</option><option value='3'>3</option></select>";
  • 写回答

2条回答 默认 最新

  • doufan6033 2012-05-20 05:04
    关注

    First of all you need to use unique id and name for each select box. Otherwise it is difficult to manage them after post.

    So you can do it something like this:

    <select name="myselect[]" id="select1">
    
    <select name="myselect[]" id="select2">
    
    <select name="myselect[]" id="select3">
    

    After form post you can get all select box values:

    print_r( $_POST['myselect'] );
    

    For number of select boxes on page you can try:

    echo count( $_POST['myselect'] );

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

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看