Get checkbox delivery and checkbox selection in PHP

Source: Internet
Author: User
Get checkbox submissions and CheckBox selection in PHP
提交页?
//js控制全选/取消全选?

?

??

??

"form1" name= "form1" method= "post" action= "receive.php" >?

"100%">?

?
???????

??????? "2">?

"center">?

"checkbox" name="all" onclick="check_all(this,'checkbox[]')" />全选/全不选

?

???????????"checkbox" name="checkbox[]" value="item1" />?

???????????1?

???????????"checkbox" name="checkbox[]" value="item2" />?

???????????2?

???????????"checkbox" name="checkbox[]" value="item3" />?

???????????3?

?????????????

?

?
???????

?
?????

??????? "2">?

??

"center">?

???????????"submit" name="Submit" value="提交" />?

????????????

?

?
???????

???
?

??

如果名字不用数组的话,php只能获取到最后一个checkbox的值?

??

receive.php?

$checkbox= $_POST['checkbox'];?

??

/*如果要获取第一个数值就直接中止输出,使用下面代码,相当于radiobox了>. <不过有点特殊而已。。*>< span="">?

for($i=0;$i<=count($checkbox);$i++)?

{?

if(!is_null($checkbox[$i]))?

{$chechvalue=$checkbox[$i];break;}?

}?

echo$chechvalue;?

??

/*如果要获取全部数值则使用下面代码*/?

for($i=0;$i<=count($checkbox);$i++)?

{?

if(!is_null($checkbox[$i]))?

{$chechvalue.=$checkbox[$i]}?

}?

echo$chechvalue;

?

?

Transferred from: http://www.cnblogs.com/freespider/archive/2011/03/18/1988308.html

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.