计数多少复选框被检查php / html [英] counting how many checkbox are checked php/html
本文介绍了计数多少复选框被检查php / html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我是php的新,我想知道如何计数一旦我点击提交检查了多少'复选框
。
例如:
Hi I am new with php and I was wondering how am i able to count how many 'checkbox'
are checked once I click on submit.
For example:
<input type = "checkbox" value = "box" name = "checkbox1"/>
<input type = "checkbox" value = "box" name = "checkbox2"/>
<input type = "checkbox" value = "box" name = "checkbox3"/>
推荐答案
Give the checkboxes names as array like
<input type = "checkbox" value = "box" name = "checkbox[]"/>
在提交之后,尝试类似
$checked_arr = $_POST['checkbox'];
$count = count($checked_arr);
echo "There are ".$count." checkboxe(s) are checked";
注意:根据您使用表单提交的方式。 $ _ GET
或 $ _ POST
您需要使用 $ _ POST [' GET 方法的 POST 方法和
$ _ GET ['checkbox']
方法。
Note : And based on the method that your form submit using...whether it is $_GET
or $_POST
you need to use $_POST['checkbox']
for POST method and $_GET['checkbox']
for the GET method.
这篇关于计数多少复选框被检查php / html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文