javascript+php 实现全选/全不选 以及对checkbox的处理
来源:互联网 发布:mysql循环语句 编辑:程序博客网 时间:2024/06/05 23:39
<?php
//connect to database
function db_link()
{
$access_id = "root";
$accesss_pwd = "831025";
$db_name = "inv";
@ $db = mysql_connect('localhost', $access_id, $accesss_pwd) or
die("Could not connect to database. Please contact with IT supporting team ASAP.");
mysql_query("SET NAMES 'GBK'");
mysql_select_db($db_name);
return $db;
}
$link = db_link();
?>
<!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>select all/unselect all</title>
<script type="text/javascript">
function setCheckboxesRange(the_form, do_check, basename, min, max){
for (var i = min; i <= max; i++) {
if (typeof(document.forms[the_form].elements[basename + i]) != 'undefined') {
document.forms[the_form].elements[basename + i].checked = do_check;
}
}
return true;
}
</script>
</head>
<body>
<?php
$sn_plant = $_POST['sn_plant'];
$sn_sales = $_POST['sn_sales'];
?>
<form name="form1" action="" method="post">
<fieldset>
<legend>criteria</legend>
<table cellpadding="0" cellspacing="1">
<tr><th>Plant:</th>
<td>
<input type="text" name="sn_plant" value="<?php echo $sn_plant;?>" maxlength="12" />
<td>
</tr>
<tr><th>Sales:</th>
<td>
<input type="text" name="sn_sales" value="<?php echo $sn_sales;?>" maxlength="12" />
<input type="submit" name="search" value="Search" />
<td>
</tr>
</table>
</fieldset>
<?php
if($_POST['search']=='Search'){
$sn_sql = "SELECT sn_id,sn_plant,sn_sales FROM sn WHERE sn_plant='".$sn_plant."' AND sn_sales='".$sn_sales."' ";
$sn_res = mysql_query($sn_sql);
$sn_num = mysql_num_rows($sn_res);
if($sn_num==0){
echo '<font color="red">Record doesn/'t exsit.</font>';
}else{
echo'<fieldset><legend>list</legend>
<table border=1>
<tr><th>chk</th><th>id</th><th>plant</th><th>sales</th></tr>';
for($i=0; $i<$sn_num; $i++){
$sn_row= mysql_fetch_array($sn_res);
echo '<tr>';
echo '<td><input type="checkbox" name="sn['.$i.']" id="rows'.$i.'" value="'.$sn_row['sn_id'].'" ></td>';
echo '<td>'.$sn_row['sn_id'].'</td>';
echo '<td>'.$sn_row['sn_plant'].'</td>';
echo '<td>'.$sn_row['sn_sales'].'</td>';
echo '</tr>';
}
echo ' <input type="hidden" name="sn_plant" value="'.$sn_plant.'">
<input type="hidden" name="sn_sales" value="'.$sn_sales.'">
</table>
</fieldset>
<a href="#" onclick="setCheckboxesRange(/'form1/', true, /'rows/', 0, '.$i.'); return false;">全选</a>/
<a href="#" onclick="setCheckboxesRange(/'form1/', false, /'rows/', 0, '.$i.'); return false;">全不选</a>
<input type="submit" name="add" value="Add">';
}
echo '</form>';
}
if($_POST['add']=='Add'){
$sn = $_POST['sn'];
$sn_plant = $_POST['sn_plant'];
$sn_sales = $_POST['sn_sales'];
//if user didn't choose it ,it's value is null,otherwise it's value equals sn_id.
//for checkbox,what we need to do is give it an unique value ,then deal with it in array.
echo 'You have chosen following items:';
foreach($sn as $key => $value){
if($sn[$key] != ""){
echo $sn[$key].',';
}
}
}
?>
</body>
</html>
- javascript+php 实现全选/全不选 以及对checkbox的处理
- javascript 实现 checkbox 全选
- javascript实现checkbox全选
- jQuery实现CheckBox全选、全不选以及获取选中的值
- jquert结合原生javascript实现的checkbox全选与全不选
- 实现列表CheckBox全选的Javascript
- CheckBox全选功能的实现--JavaScript
- 用Javascript实现checkbox全选、全不选
- Javascript实现CheckBox的全选与取消全选的代码
- Javascript实现CheckBox的全选与取消全选的代码
- Javascript实现CheckBox的全选与取消全选的代码
- CHECKBOX"全选"的JavaScript
- 实现全选和取消全选(JavaScript控制CheckBox 的全选与取消全选)
- 关于checkbox的全选/全不选的处理
- JavaScript checkbox全选与全不选的切换
- checkbox全选javascript代码实现
- JavaScript简单实现checkbox全选
- 使用JavaScript实现checkbox全选
- property和attribute的区别
- C++程序设计之四书五经 (下) Zz
- 第八章 ORACLE 索引 INDEXES (一)
- HTTP 响应码 && HTTP 信息头
- DOS高级命令
- javascript+php 实现全选/全不选 以及对checkbox的处理
- 第七章 Redo and Undo (二)
- 统计术语中英文对照
- 第七章Redo and Undo (一)
- oracle10 linux9 修改listener监听端口遇到ORA-28547错误
- 日志的设计
- 如何成为ORACLE DBA
- ssh-keygen的问题
- 软件破解 偶遇句