[英]Execute query on button click If checkbox is checked
如果我单击提交按钮时选中了复选框,我想执行脚本。
我的overview.php
有以下代码段:
<table style="width: 100%; font-size: 11;">
<tr>
<td colspan="6">
<form method="post" action="update.php" target="_blank">
<script language="JavaScript">
function toggle(source) {
checkboxes = document.querySelectorAll("input[name^='box[']");
for(var i=0, n=checkboxes.length;i<n;i++) {
checkboxes[i].checked = source.checked;
}
}
</script>
<input type="submit" name="update" value="Update - LoL / BoL">
<input type="checkbox" onClick="toggle(this)" name="All" value="All"> Select all
</form>
</td>
</tr>
<tr>
<th>ve067</th>
<th>ve378</th>
<th>ve724</th>
<th>ve725</th>
<th>ve726</th>
<th>ve727</th>
</tr>
<tr>
<td>
<form method="post" action="update.php">
<input type="checkbox" name="box[1]" value="ve067_LB1"> LeagueBot 1<br>
<input type="checkbox" name="box[2]" value="ve067_LB2"> LeagueBot 2<br>
<input type="checkbox" name="box[3]" value="ve067_LB3"> LeagueBot 3<br>
<input type="checkbox" name="box[4]" value="ve067_LB4"> LeagueBot 4<br>
</form>
</td>
</tr>
</table>
这是我的update.php
的代码片段:
<?php
if(isset($_POST['update'] && $_POST['box[4]']) {
// code here
}
?>
但这对我不起作用。
解决方案:考虑以下JSFiddle
说明:这将验证是否已至少选中复选框“ box [4]”。
这里的“键”代码是下一行的return
函数。
<input type="submit" name="update" value="Update - LoL / BoL" onclick="return validate();">
更新:旨在容纳注释中提供的其他信息。
请记住:此处的验证是在客户端完成的,因此不需要先查询服务器( PHP
)
您可以按照我在pastebin上的帖子中提到的那样进行操作
希望它对您有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.