gpt4 book ai didi

javascript - PHP:单击即可获取多个复选框的值,也可以单击获取每个值的值

转载 作者:行者123 更新时间:2023-12-02 16:13:18 25 4
gpt4 key购买 nike

I have a question regarding a php form. I've added a checkbox I would like it to select all in one click and click it separately.

<form name=myform action="addcanteen.php" method=post>
<table><tr><td width="11%"> Date:</td><td width="89%"><input type="date" name="cdate" id="cdate"/></td></tr></table>
<table border="1" bgcolor="#F5F9C1">
<tr>
<!--<th>ID</th>-->
<th>Name</th>
<td><!--<input type="text" id="datepicker">-->
<input type="checkbox" id="selectall" name="chk[]"/></td>
<td align="center">coffee</td>
<td align="center">tea</td>
</tr>
<?php while($row=mysql_fetch_array($result))
{
?>
<tr>
<?php /*?><td><?php echo $row['emp_id'];?></td><?php */?>
<td><?php echo $row['emp_name'];?></td>

<td align="center"><input type="checkbox" class="name" name="chk1[]" value="<?php echo $row['emp_name'];?>"/></td>

<td><input type="text" name="coffee[]" id="coffee" value="" /></td>
<td><input type="text" name="tea[]" id="tea" value=""/></td>
</tr>
<?php } ?>
<tr>
<td>
</td>
<td>
</td>
<td align="center">
<input type="submit" class="button" name="submit" id="submit" value="submit"/>
</td>
</tr>
</table>
</form>

here is the php code for the insertion, everything works there except the insertion of single checkbox selection.

<?php
include(dbcon.php);
date_default_timezone_set('UTC');
/*$d=date("D");*/
$date=date("d");
$month=date("m");
$year=date("Y");
$fd=date("d-m-Y");
if(isset($_POST['submit']))
{
$cdate=$_POST['cdate'];
//$emp_id=$_POST['emp_id'];
$checkbox1=$_POST['chk1'];
$tea=$_POST['tea'];
$coffee=$_POST['coffee'];
/*$dd=date("d-m-y");*/
for ($i=0; $i<sizeof($checkbox1);$i++)
{
$query1="INSERT INTO canteen(name,coffee,tea,date)VALUES('".$checkbox1[$i]."','".$coffee[$i]."','".$tea[$i]."','$cdate')";
$sql1=mysql_query($query1);
}
}
header("location:canteen.php");
?>

最佳答案

我明白你的意思,但我建议你在 JavaScript 中使用映射函数并引用类。 For more info refer this link

关于javascript - PHP:单击即可获取多个复选框的值,也可以单击获取每个值的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29915704/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com