是不是如果选中该checkbox,$_POST['select[1]']就会等于1呢;-------------------------------------------------yes

解决方案 »

  1.   

    <form enctype='multipart/form-data' action="" method="POST" name="submit" >
    <?
    for($i=1;$i<10;$i++)
    {
    ?>
    <td width="100%" ><input type="checkbox" name="select[<?echo $i?>]" value="<?echo $i?>" ></input></td>
    <?
    }
    ?>
    </form>
    我这样写行吗??
    这样该怎么取value的值呢??
      

  2.   

    for($i=1;$i<10;$i++)
    {
    $name = 'select['.$i.']';
    if($_POST[$name])
    {
         $j++;
                  $taskId[$j]=$_POST[$name]; 
    }
    }
    我这样怎么都取不到$_POST[$name]的值。
    是不是我哪里写错了。
    请各位朋友帮帮我。:(
      

  3.   

    问题出在你的表单名字select[<?echo $i?>]"的[]上,这个数据POST到服务器以后$_POST里面的数值变成了
    Array
    (
        [select] => Array
            (
                [1] => 1
                [3] => 3
                [5] => 5
                [7] => 7
                [9] => 9
            ))
    这个你可以通过print_r($_POST)看到,而不是所希望的
    Array
    (
        [select[1]] => 1
        [select[3]] => 3
        [select[5]] => 5
        [select[7]] => 7
        [select[9]] => 9
    )因此你需要改变一下你的表单的命名方式。
    至于为什么出现这个我就不知道了,还希望知道原因的大虾能指点一下。
      

  4.   

    <form enctype='multipart/form-data' action="" method="POST" name="submit" >
    <?
    for($i=1;$i<10;$i++)
    {
    ?>
    <td width="100%" ><input type="checkbox" name="select[]" value="<?echo $i;?>" ></input></td>
    <?
    }
    ?>
    </form>
    and use $_POST['select'][$i] to get the data.($i>=0)
      

  5.   

    <form enctype='multipart/form-data' action="" method="POST" name="submit" >
    <?
    for($i=1;$i<10;$i++)
    {
    ?>
    <td width="100%" ><input type="checkbox" name="select[]" value="<?echo $i;?>" ></input></td>
    <?
    }
    ?>
    </form>
    for($i=1;$i<10;$i++)
    {
    if( $_POST['select'][$i])
    {
         $j++;
         $taskId[$j]=$_POST['select'][$i]); 
    }
    }
    现在我已经改成这样了,
    可是if语句还是进不去,取得的$_POST['select'][$i的值还是为空。
      

  6.   

    <table>
    <form enctype='multipart/form-data' action="" method="POST" name="submit" >
    <?
    for($i=1;$i<10;$i++)
    {
    ?>
    <tr><td width="100%" ><input type="checkbox" name="select[]" value="<?echo $i;?>" ></input><?echo $i;?></td></tr>
    <?
    }
    ?>
    <tr><td width="100%" ><input type="submit" name="sub" value="submit" ></input></td></tr>
    </form>
    </table>
    <?
    print_r($_POST);
    $j=0;                //初始化赋值
    for($i=0;$i<10;$i++) //$i=1 改为 $i=0
    {
    if( $_POST['select'][$i] )
    {
         $j++;
         $taskId[$j]=$_POST['select'][$i];  //此处多 “)”
    }
    }
    print_r($taskId);
    ?>
      

  7.   

    如果提交的都是数字,最好将 
    if( $_POST['select'][$i] )
    改为
    if( is_numeric($_POST['select'][$i]) )
      

  8.   

    在checkbox的"name"后面都用相同的名字,并且在名字后面加上"[]",例如"name[0]","name[1]",依次类推,在获取的时候自然就是一个数组,直接用if就可以了
      

  9.   

    哦,谢谢谢谢,谢谢大家,这样可以了。对了,再问一个问题。
    echo "<script LANGUAGE=JavaScript>window.confirm('$String');</script>";
    这个window.confirm()怎么知道 用户取的是yes or no呢??
      

  10.   

    对了,再问一个问题。
    echo "<script LANGUAGE=JavaScript>window.confirm('$String');</script>";
    这个window.confirm()怎么知道 用户取的是yes or no呢??
    ------------------------------------------------------------------------------*** 这个问题GOOGLE或MSDN都能解决 ***confirm Method--------------------------------------------------------------------------------Displays a confirmation dialog box that contains an optional message as well as OK and Cancel buttons.SyntaxbConfirmed = window.confirm( [sMessage])
    ParameterssMessage Optional. String that specifies the message to display in the confirmation dialog box. If no value is provided, the dialog box does not contain a message. Return ValueBoolean. Returns one of the following possible values:true The user clicked the OK button. 
    false The user clicked Cancel button. ResThe title bar of the confirmation dialog box cannot be changed.Standards InformationThere is no public standard that applies to this method.