php checkbox復(fù)選框值的獲取與checkbox默認(rèn)值輸出方法
更新時間:2010年05月15日 18:54:33 作者:
php獲取 checkbox復(fù)選框值的方法,checkbox在php讀取值時要用數(shù)組形式哦,我們讀取這些值用php post獲取是以一個array形式哦。
php獲取 checkbox復(fù)選框值的方法
<html xmlns="http://www.dbjr.com.cn/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>php獲取 checkbox復(fù)選框值的方法</title>
</head>
<body>
<form name="form1" method="post" action="">
<label>
<input type="checkbox" name="checkbox[]" value="復(fù)選一">
復(fù)選一
</label>
<label>
<input type="checkbox" name="checkbox[]" value="復(fù)選二">
</label>
復(fù)選二
<label>
<input type="checkbox" name="checkbox[]" value="復(fù)選三">
</label>
復(fù)選三
<label>
<input type="checkbox" name="checkbox[]" value="復(fù)選四">
</label>
復(fù)選四
<label>
<input type="submit" name="Submit" value="提交">
</label>
</form>
</body>
</html>
<?
if( $_POST )
{
$value = $_POST['checkbox'];
echo '你選擇了:'.implode(',',$value);
//由于checkbox屬性,我們必須把checkbox復(fù)選擇框的名字設(shè)置為一個如果checkbox[],這樣php才能讀取,以數(shù)據(jù)形式,否則不能正確的讀取checkbox復(fù)選框的值哦。//腳本之家 jb51.net 整理
}
?>
checkbox在php讀取值時要用數(shù)組形式哦,我們讀取這些值用php post獲取是以一個array形式哦,
<!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獲取多選框checkbox值</title>
</head>
<body>
<?php
$area_arr = array();
if($_GET['action']=="submit"){
$area_arr = $_POST['area'];
}
echo "您選定的地區(qū)為: ";
foreach ($area_arr as $k=>$v){
echo $v." ";
}
?>
<form id="form1" name="form1" method="post" action="?action=submit">
<p>河北
<label>
<input type="checkbox" id="area" name="area[]" value="河北">
</label>
</p>
<p>河南
<label>
<input type="checkbox" id="area[]" name="area[]" value="河南">
</label>
</p>
<p>山西
<label>
<input type="checkbox" id="area[]" name="area[]" value="山西">
</label>
</p>
<p>山東
<label>
<input type="checkbox" id="area[]" name="area[]" value="山東">
</label>
</p>
<p>江蘇
<label>
<input type="checkbox" id="area[]" name="area[]" value="江蘇">
</label>
</p>
<p>浙江
<label>
<input type="checkbox" id="area[]" name="area[]" value="浙江">
</label>
</p>
<p>
<label>
<input type="submit" name="Submit" value="提交">
</label>
</p>
</form>
</body>
</html>
php checkbox默認(rèn)選擇問題(都是利用的這種原理)
<input name="jb51" type="checkbox" value="jiaju" <?php if($myrow[fujia_jiaju]) echo("checked");?>>
復(fù)制代碼 代碼如下:
<html xmlns="http://www.dbjr.com.cn/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>php獲取 checkbox復(fù)選框值的方法</title>
</head>
<body>
<form name="form1" method="post" action="">
<label>
<input type="checkbox" name="checkbox[]" value="復(fù)選一">
復(fù)選一
</label>
<label>
<input type="checkbox" name="checkbox[]" value="復(fù)選二">
</label>
復(fù)選二
<label>
<input type="checkbox" name="checkbox[]" value="復(fù)選三">
</label>
復(fù)選三
<label>
<input type="checkbox" name="checkbox[]" value="復(fù)選四">
</label>
復(fù)選四
<label>
<input type="submit" name="Submit" value="提交">
</label>
</form>
</body>
</html>
<?
if( $_POST )
{
$value = $_POST['checkbox'];
echo '你選擇了:'.implode(',',$value);
//由于checkbox屬性,我們必須把checkbox復(fù)選擇框的名字設(shè)置為一個如果checkbox[],這樣php才能讀取,以數(shù)據(jù)形式,否則不能正確的讀取checkbox復(fù)選框的值哦。//腳本之家 jb51.net 整理
}
?>
checkbox在php讀取值時要用數(shù)組形式哦,我們讀取這些值用php post獲取是以一個array形式哦,
復(fù)制代碼 代碼如下:
<!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獲取多選框checkbox值</title>
</head>
<body>
<?php
$area_arr = array();
if($_GET['action']=="submit"){
$area_arr = $_POST['area'];
}
echo "您選定的地區(qū)為: ";
foreach ($area_arr as $k=>$v){
echo $v." ";
}
?>
<form id="form1" name="form1" method="post" action="?action=submit">
<p>河北
<label>
<input type="checkbox" id="area" name="area[]" value="河北">
</label>
</p>
<p>河南
<label>
<input type="checkbox" id="area[]" name="area[]" value="河南">
</label>
</p>
<p>山西
<label>
<input type="checkbox" id="area[]" name="area[]" value="山西">
</label>
</p>
<p>山東
<label>
<input type="checkbox" id="area[]" name="area[]" value="山東">
</label>
</p>
<p>江蘇
<label>
<input type="checkbox" id="area[]" name="area[]" value="江蘇">
</label>
</p>
<p>浙江
<label>
<input type="checkbox" id="area[]" name="area[]" value="浙江">
</label>
</p>
<p>
<label>
<input type="submit" name="Submit" value="提交">
</label>
</p>
</form>
</body>
</html>
php checkbox默認(rèn)選擇問題(都是利用的這種原理)
復(fù)制代碼 代碼如下:
<input name="jb51" type="checkbox" value="jiaju" <?php if($myrow[fujia_jiaju]) echo("checked");?>>
相關(guān)文章
使用php通過Socket進行發(fā)信源碼,支持發(fā)信認(rèn)證
使用php通過Socket進行發(fā)信源碼,支持發(fā)信認(rèn)證...2006-10-10apache+mysql+php+ssl服務(wù)器之完全安裝攻略
apache+mysql+php+ssl服務(wù)器之完全安裝攻略...2006-09-09PHP CURL CURLOPT參數(shù)說明(curl_setopt)
這篇文章主要介紹了PHP CURL CURLOPT參數(shù),需要的朋友可以參考下2013-09-09