我用的是复选框,但是我提交过来的时候总是只得到一个值,请大家帮帮忙啊

解决方案 »

  1.   

    复选框名字用数组来表示:<input type="checkbox" name="checkbox[]" value="">
    服务器端取得值为数组,就可以处理了.
      

  2.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>无标题文档</title>
    </head>
    <script language="javascript"> 
    function selectAll() 

    for(var i=0;i<document.form1.del[].length;i++) 

    document.form1.del[][i].checked=false; 


    function unSelect() 

    for(var i=0;i<document.form1.del[].length;i++) 

    if(document.form1.del[][i].checked) 

    document.form1.del[][i].checked=false; 

    else 

    document.form1.del[][i].checked=true; 



    </script> 
    <body>
    <form name="form1" method="post" action="delPost.php">
      <table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#000000">
        <tr bgcolor="#FFFFFF">
          <td width="96" height="25"><div align="center">用户名</div></td>
          <td width="136" height="25"><div align="center">密码</div></td>
          <td width="115"><div align="center">登陆时间</div></td>
          <td width="148"><div align="center">
            <input name="delete" type="submit" id="delete" value="删除">
            <input type="button" name="Submit" value="全选" onclick="selectAll();">
            <input type="button" name="Submit2" value="反选" onclick="unSelect();">
          </div></td>
        </tr>
        <?php
      require_once("mysql.php");
      $sql="select * from admin";
      $result=dbConn($sql);
      while ($array=mysql_fetch_array($result["rs"])){
      ?>
        <tr bgcolor="#FFFFFF">
          <td height="25"><div align="center">
              <?=$array["a_zhanghao"]?>
          </div></td>
          <td height="25"><div align="center">
              <?=$array["a_mima"]?>
          </div></td>
          <td><div align="center">
              <?=$array["login_time"]?>
          </div></td>
          <td><div align="center">
            <input name="del[]" type="checkbox" id="del[]" value="<?php echo $array["a_id"]?>">
    </div></td>
        </tr>
        <?php
    }
    ?>
      </table>
    </form>
    </body>
    </html>
    调用的地方缺少对象,是怎么会事啊?
      

  3.   

    <form action="?" method="post">
    <input type="checkbox" name="checkbox[1]" value="a">
    <input type="checkbox" name="checkbox[2]" value="b">
    <input type="checkbox" name="checkbox[3]" value="c">
    <input type="submit">
    </form>
    程序
    <?
    if(!empty($_POST['checkbox']))
    foreach($_POST['checkbox'] as $k=>$v){
      echo $k.'='.$v.'<br>';
    }
    ?>
      

  4.   

    写法不对,请使用getElementsByName
    将javascript改成以下试试
    ===============================
    <script language="javascript">var sid = document.getElementsByName('del[]');function selectAll()
    { for(var i=0;i<sid.length;i++)
    {
    sid[i].checked=true;
    }
    }
    function unSelect()
    {
    for(var i=0;i<sid.length;i++)
    {
    if(sid[i].checked)
    {
    sid[i].checked=false;
    }
    else
    {
    sid[i].checked=true;
    }
    }
    }
    </script>