Php method for obtaining the checkbox check box Value
Copy codeThe Code is as follows:
<Html xmlns = "http://www.jb51.net/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> php method for obtaining the checkbox check box value </title>
</Head>
<Body>
<Form name = "form1" method = "post" action = "">
<Label>
<Input type = "checkbox" name = "checkbox []" value = "check">
Check item 1
</Label>
<Label>
<Input type = "checkbox" name = "checkbox []" value = "2">
</Label>
Check Option 2
<Label>
<Input type = "checkbox" name = "checkbox []" value = "check three">
</Label>
Check 3
<Label>
<Input type = "checkbox" name = "checkbox []" value = "check box">
</Label>
Check item 4
<Label>
<Input type = "submit" name = "Submit" value = "submit">
</Label>
</Form>
</Body>
</Html>
<?
If ($ _ POST)
{
$ Value = $ _ POST ['checkbox'];
Echo 'you selected:'. implode (',', $ value );
// Because of the checkbox attribute, we must set the name of the checkbox re-selection box to one if checkbox [], so that php can read data in the form of data, otherwise, the value of the checkbox check box cannot be correctly read. // Tidy up jb51.net
}
?>
Checkbox should be in the array format when reading values in php. We can read these values using php post to get them as an array,
Copy codeThe Code is as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> php obtains the checkbox value of multiple selection boxes. </title>
</Head>
<Body>
<? Php
$ Area_arr = array ();
If ($ _ GET ['action'] = "submit "){
$ Area_arr =$ _ POST ['are'];
}
Echo "the region you selected is :";
Foreach ($ area_arr as $ k => $ v ){
Echo $ v ."";
}
?>
<Form id = "form1" name = "form1" method = "post" action = "? Action = submit ">
<P> Hebei
<Label>
<Input type = "checkbox" id = "area" name = "area []" value = "Hebei">
</Label>
</P>
<P> Henan
<Label>
<Input type = "checkbox" id = "area []" name = "area []" value = "Henan">
</Label>
</P>
<P> Shanxi
<Label>
<Input type = "checkbox" id = "area []" name = "area []" value = "Shanxi">
</Label>
</P>
<P> Shandong
<Label>
<Input type = "checkbox" id = "area []" name = "area []" value = "Shandong">
</Label>
</P>
<P> Jiangsu
<Label>
<Input type = "checkbox" id = "area []" name = "area []" value = "Jiangsu">
</Label>
</P>
<P> Zhejiang
<Label>
<Input type = "checkbox" id = "area []" name = "area []" value = "Zhejiang">
</Label>
</P>
<P>
<Label>
<Input type = "submit" name = "Submit" value = "submit">
</Label>
</P>
</Form>
</Body>
</Html>
Php checkbox default selection problem (this principle is used)
Copy codeThe Code is as follows:
<Input name = "jb51" type = "checkbox" value = "jiaju" <? Php if ($ myrow [fujia_jiaju]) echo ("checked") ;?>>